The form Element <form>...</form>

The  action attribute provides the location (URL) of the application or script(sometimes called the action page) that will be used to process the form.

 

There are only two methods for sending this encoded data to the server:

POST or GET, indicated using the  method attribute in the  form element. The

method is optional and will default to GET if omitted.

 

When the form’s method is set to POST, the browser sends a separate server

request containing some special headers followed by the data. Only the

server sees the content of this request, thus it is the best method for sending

secure information such as credit card or other personal information.

The POST method is also preferable for sending a lot of data, such as a

lengthy text entry, because there is no character limit as there is for GET.

 

The GET method is appropriate if you want users to be able to bookmark

the results of a form submission (such as a list of search results). Because the

content of the form is in plain sight, GET is not appropriate for forms with

private personal or financial information. In addition, GET may not be used

when the form is used to upload a file.

In this chapter, we’ll stick with the more prevalent POST method. Now that

we’ve gotten through the technical aspects of the  form element, we can take

on the real meat of forms: form controls.

 

The name attribute provides the variable name for the control. In this exam-

ple, the text gathered by a  textarea element is defined as the “comment”

variable:

<textarea name="comment"rows="4" cols="45" placeholder="Leave us a

comment."></textarea>

When a user enters a comment in the field(“This is the best band ever!”), it

would be passed to the server as aname/value (variable/content) pair like this:

comment=This%20is%20the%20best%20band%20ever%21

All form control elements must includea  name attribute so the form-process-

ing application can sort the information.

 


评论

© ID4333709 | Powered by LOFTER