In most cases, we specify another URL address to process the form content to the Action attribute, but in some cases, we need to submit the form data to ourselves. In this case, how should we specify the Action attribute value?
<? Php
If (isset ($ _ POST ['action']) & $ _ POST ['action'] = 'submitted '){
Print '<pre> ';
Print_r ($ _ POST );
Print '<a href = "'. $ _ SERVER ['php _ SELF '].'"> Please try again </a> ';
Print '</pre> ';
} Else {
?>
<Form action = "<? Php echo $ _ SERVER ['php _ SELF '];?> "Method =" POST ">
Name: <input type = "text" name = "personal [name]"> <br>
Email: <input type = "text" name = "personal [email]"> <br>
Beer: <br>
<Select multiple name = "beer []">
<Option value = "warthog"> Warthog
<Option value = "guinness"> Guinness
</Select> <br>
<Input type = "hidden" name = "action" value = "submitted">
<Input type = "submit" name = "submit" value = "submit me! ">
</Form>
<? Php
}
?>
The above code implements the form submission to yourself (Note: use $ _ HTTP_POST_VARS to replace the $ _ Post variable in the following code in PHP4.1.0 or earlier versions ). Here, the Server variable $ _ Server is used to obtain the URL address of the current page and assign it to the Action attribute of the form. A small trick is used here to determine whether a POST request or GET request is received by the server. Add a Hidden variable to the form. when processing the request, we use the isset function to check whether this Hidden variable is set. Then, we can determine whether the request uses the POST or GET method.