|How a Form Renders||id= vs name=|
|HTML to Generate a Form||HTML5|
|Conversation with the Server||Links|
A form lets the user fill in the blanks, then send just the data to the server. It does not do any validation. That all must be handled by the server. A more advanced validation system is called XFORMS.
Here is how a typical form renders
Here is the HTML to generate it:
In this case the forms sends its data to a locally running test echoserver waiting for input on port 8081. What gets sent to the server looks something like this, 640 bytes:The parameters arrive after a set of standard header fields separated from the by a blank line. The datafields are urlencoded, e.g. space appears as %40. Servlets have method for decoding and parsing all this information. Had I not ticked the sendAds checkbox the &sendAds=yes would be missing entirely.
In English that message means:
The method can be either GET for short idempotent queries or POST for more complex ones. You can embed more elaborate HTML formatting commands inside the <form… </form> sandwich. The name fields identify the data to the server. the id fields help link together a label with its data field.
Here is the HTML to generate the combo form:
To turn on the option to allow multiple choices, some older browsers would have you code plain multiple instead of multiple=multiple and to mark an option as selected, selected instead of selected=selected. selected=selected is the new idiotic XHTML-compatible way of specifying a Boolean field option. Here is typically what gets sent back to the server:In English this says:
Note how the allergies field gets sent more than once, once for each selected value.
<optgroup can group <option. This results is a collapsed list of possibilities, making a long list more compact and easy to navigate.
Forms don’t have the equivalent of a Java JTable. The best you can do is use a giant radio button, or a checkbox on each row, to select a row, then have the server resend that row as a single record. Alternatively, you can put the selection into a giant <select <option list. You could also create a link per row and have that display the selected row by itself. Similarly you can cobble together ways to delete one or multiple records.
If you leave out the action tag, it defaults to the URL (Uniform Resource Locator) of the page containing the form.
Form tags may not be nested, though they may appear either inside or enclosing a table.
If the expression returned is true, the submit proceeds.
For some fancy tricks dynamically changing the GET url on the fly and dynamically changing the name of the fields and dynamically adding extra decorative fields, look at the source for general search. I have not yet figured out how to pull off the same stunts for POST without using an Applet.
There is form mailto feature to have the contents of the form emailed to you. I don’t recommend this because:
If your form is https:, temporarily convert it to http: so that you can snoop on the exchanges with Wireshark.
You will notice in the example above that each field in the form was named twice, once with name= and once with id=. What’s the difference? The short answer is, use both and don’t worry about it. But if you want to understand this goofiness, here’s the skinny:
Another way to get buttons is to use *.png file as the background, or a generic long gradient bar image the way Oracle does. You just use a slice of it.
HTML5 offers some new features for forms:
available on the web at:
optional Replicator mirror
Please email your feedback for publication, letters to the editor, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : . If you want your message, your name or email kept confidential, not considered for public posting, please explicitly specify that. Unless you state otherwise, I will treat your message as a letter to the editor that I may or may not publish in the feedback section. After that, it will be too late to retract it. If you disagree with something I said, especially when sending an ad-hominem attack, a rant composed mainly of obscenities or a death threat, please quote the offending passage and cite the web page where you found it, tell me why you think it is wrong, and, if possible, provide some supporting evidence. I can’t very well fix erroneous or ambiguous text if I can’t find it.
Your face IP:[220.127.116.11]
|Feedback||You are visitor number 11.|