How PHP submits the form to itself

Source: Internet
Author: User
Using PHP for Web development, the use of forms (form) is ubiquitous, and its properties action and method allow you to specify the URL to which the form's content is to be sent and how to send the form data to the server. In most cases we specify another URL address to handle the contents of the form to the Action property, but there are also some cases where the form data needs to be submitted to itself. How do we specify the Action property value at this time?

Php
if (isset($_post['action']) &&$_post['action'] == ' submitted ' ){
Print '

' ;

Print_r ($_post);
Print ' '. $_server ['php_self'] . ' ">pleasetryagain ' ;

Print '
' ;
} Else {
?>
< formaction = " " Method = " POST " >
Name : < InputType = " text " name = " Personal[name] " >< BR >
Email : < InputType = " text " name = " Personal[email] " >< BR >
Beer : < BR >
< Selectmultiplename = " beer[] " >
< optionvalue = " Warthog " > Warthog
< optionvalue = " Guinness " > Guinness
Select><BR>
<InputType="Hidden"name="Action"value="submitted">
<InputType="Submit"name="Submit"value="submitme!">
form>
Php
}
?>

The code above implements the submission of the form to itself ( Note: Use $_http_post_vars instead of the $_post variable in the code below in the PHP4.1.0 version ). The server variable $_server is used here to get the URL address of the current page and assign it to the form's Action property. Here is a small trick used by the server to determine whether the URL request is a POST request or a GET request. is to add a hidden variable to the form, and when processing the request we detect whether the hidden variable is set by the isset function, thus determining if the request uses a post or get method.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The above describes how PHP submits the form to itself, including aspects of the content, I hope the PHP tutorial interested in a friend helpful.

  • 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.