PHP is used for web development. The use of forms is everywhere and its attributes are used.ActionAndMethodYou can specify the URL of the form content to be sent and how to send the form data to the server. In most cases, we specify another URL for processing the form contentActionAttribute, but in some cases, you need to submit the form data to yourself. How should we specifyActionWhat about the 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 code above implements submitting the form to yourself (Note: For versions earlier than php4.1.0, use$ _ Http_post_varsReplace$ _ PostVariable). Here, the server variable $ _ server is used to obtain the URL address of the current page and assign it toActionAttribute.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.IssetThe function checks whether the Hidden variable is set, and determines whether the request uses the post or get method..