Submit the PHP form to yourself

Source: Internet
Author: User
Tags php form

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.