|
home—lects—exams—hws
D2L—breeze (snow day)
<input type='checkbox' name='cb1' value='milk' id='cbOne' checked='checked' /> |
<input type='text' name='txt1' size='10' maxlength='8' id='txtone' /> |
<input type='radio' name='age' value='over50' id='age-over50' /> <br/> <input type='radio' name='age' value='30to50' id='age-30to50' /> <br/> <input type='radio' name='age' value='under30' id='age-under30' /> <br/> |
<textarea name='comments' id='komments' rows='3' cols='30'> Initial Contents </textarea> |
(I'm not really sure why text areas are different from
from checkboxes/radio-buttons/text-fields1.
It'd seem more sensible to either have a single tag
<select name='title' id='tytle'> <option value = 'mr'>Mr.</option> <option value = 'ms'>Ms.</option> <option value = 'mrs'>Mrs.</option> <option value = 'miss'>Miss</option> </select> |
<input type='submit' value='Submit Data to Server' /> |
<input type='reset' value='Clear Form' /> |
Gotcha: While <input name='aNodeName'/> uses the name attribute to pass information to the action/request, the html <label for='aNodeId'>… uses id to refer to the DOM node of the current tree. (It makes good sense, but takes a moment of thought.)
Q: But how is information communicated from a web form (pure html) to a php program?
A: When you click 'submit', the HTML makes a page-request to the page specified by the form's "action" attribute.
(Presumably it's a php page.)
The page-request incudes extra information about what html input fields had been selected, etc.,
as part of the http request.
The server gets that request and invokes the php file as normal, but it also
pre-initializes an array of values for the program — and it fills that array with
the extra information contained in the page-request.
Best practice:
when including a
It's not so much that you always need both name and id, but it's not uncommon, and you should really name them the same thing. (This page made them slightly different, just so you could see the difference, and understand which is used where).
Testing, testing:
- samp inside kbd: select File » Save As….
- kbd inside samp: The output was Your name is iblarand.
- kbd inside kbd select File » Save As….
1
Note that everything the HTML designers bundled together
under the
2 Idempotent is not quite the same as having-no-side-effect: For example, if you add-to-shopping-cart-unless-item-already-there, you can change state, but still be idempotent. ↩
3
Well, “irrelevant” state-change is okay:
you can update log files and update cookie-timestamps,
w/o violating the spirit of a
4
And later, when we talk about sticky-forms,
I'll suggest
“customer-info-edit.html”
which
home—lects—exams—hws
D2L—breeze (snow day)
©2015, Ian Barland, Radford University Last modified 2015.Sep.28 (Mon) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |