How Website Design and Programming ? Introduction to Web Forms

 

 

There is practically no website without at least a form on one of its pages. Forms are useful to collect data from website visitors and users. Once the user submits the form to the server, a form processing script must get the form data, validate that the user input matches the expected format for each field (e.g: email address field must be a string of text with the format of a valid email address) and process this information as desired. The script may save it into a database, send it by email or just do some processing with it and display the result. Validating the user input is essential to prevent malicious users from damaging your site. A form definition in HTML starts with the form tag and ends with the /form tag. This tag can have several attributes like method (GET or POST), and action (the URL of the form processing script). If using the GET method, the form data is encoded in the action URL. This method is recommended when a form is a query form. With the POST method, the form data is to appears within a message body. This is the recommended method when the form will be used to update a database, send an email, or make any action other than just retrieving data. The form fields are used to collect the data. Generally, a label is placed by each field, so the user knows what data to input. There are different kinds of fields, among them: ú Textboxes ú Textareas ú Drop-downs ú Multi-select ú File ú Radio buttons ú Checkboxes ú Buttons ú Hidden The hidden fields are used to send some data that the user does not need to see, along with the form. An example of this could be a form number, so the form processing script identifies which form has been submitted. The File field allows users to upload a file. The form processing script will get the file together with the rest of the form data. For this field to work properly, you need to include this attribute in the form tag: enctype=?multipart/form-data?. Buttons are used to submit or reset the form. Refer to an HTML guide for a full description of the attributes and syntax of each tag. You may find a guide among many other sites. When the form is complex, it is useful to group fields in areas using the fieldset tag. Just place the fieldset tag, then optionally a legend Section Name /legend tag, then all the pertinent form fields, and the /fieldset tag after them. It is possible to use CSS (Cascading Style Sheets) or inline styles to change the look of the form controls. You can bring your forms to a different level by combining them with the usage of a scripting language like JavaScript. You can make the form react immediately to certain events, like the user clicking on a control, or a field changing its value. You can highlight the field that has the focus, for example. Or count how many characters have been entered in a text box or a text area. You can make calculations and display the results automatically.

Enjoyed this article? Stay informed by joining our newsletter!

Comments

You must be logged in to post a comment.

About Author