☰ خطة العام · تكنولوجيا المعلومات والاتصالات (بالإنجليزية)

The converter as a PHP web page

الأسبوع 7 · الوحدة ١ الموضوع الثالث: محوّل الأعداد كصفحة ويب بلغة PHP: النموذج وأدوات التحكم وكود PHP وعرض النتيجة · 3 دروس
1

From window to web page: a form with three buttons

ICT Secondary 3 Term 1, Unit 1, Topic 3: pp. 37–50
GoalDescribe the converter page: its form, the text box and three buttons, and where the three results appear.
New words
dynamic page · a web page whose content is built by code on the server each time it is asked forform · the part of a page that collects what the visitor types or chooses and sends it to the serversubmit button · a button that sends the formmethod (post) · the way of sending in which the values travel inside the request, not in the address
Explanation

Last week the converter was a window with six radio buttons. A web page does the same job in another way. It has no radio buttons: it has three buttons, and the button you press tells the page which system the typed number is in: binary, decimal or hexadecimal. The page is a form with one text box named number and three submit buttons. The method is post, which sends the typed value inside the request. The form has no action, so it is sent back to the same page. Under the form the page shows three results, one for each system. A page whose content depends on what the visitor sends, and is built by code on the server every time, is called a dynamic page. The HTML in this lesson is only the empty frame; PHP, in the next lesson, fills it.

Worked examples
Html
1<form method="post">
2  <input type="text" name="number">
3  <input type="submit" name="btnBin" value="Typed number is binary">
4  <input type="submit" name="btnDec" value="Typed number is decimal">
5  <input type="submit" name="btnHex" value="Typed number is hexadecimal">
6</form>
This is the form of the page, in HTML. The names (number, btnBin, btnDec, btnHex) are what PHP will use to find the values.
Button nameThe typed number isFunction that gives the decimal number
btnBinbinarybindec
btnDecdecimalnone: it is decimal already
btnHexhexadecimalhexdec
Each button has a name, and the name says what the typed number is. The last column shows which ready PHP function will turn it into a decimal number.
Window (Week 6)Page (this week)
choosing the systemssix radio buttons in two framesthree buttons: the button says what is typed
what starts the workthe click event of one buttonthe form being sent by one of the buttons
where the answer appearsa message boxthree result lines in the page
The window of Week 6 and the page of this week do the same work in different ways.
Class activity

On paper, draw the page of a converter that turns hours into minutes. Label the text box, the button (give it a name for PHP) and the place of the result. Then say what the method of the form is and what happens when there is no action.

Practice
1
Which button names does the converter page use?
2
What does the method post do?
3
What is a dynamic page?
4
Which part of the page tells PHP that the typed number is hexadecimal?