Home  >  Article  >  Backend Development  >  Submit PHP form to yourself_PHP tutorial

Submit PHP form to yourself_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:51:22763browse

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. How should we specify the Action attribute value at this time?
if (isset($_POST['action']) && $_POST['action'] == 'submitted') {
print '

'; <br><br> print_r($_POST); <br> print '<a href="'. $_SERVER['PHP_SELF'] .'">Please try again</a>'; <br><br> print '
';
} else {
?>

Name:

Email:

Beer:




< ;input type="submit" name="submit" value="submit me!">

}
?>
above The code realizes submitting the form to yourself (note: in versions before PHP4.1.0, please use $_HTTP_POST_VARS instead of the $_Post variable in the code below). The server variable $_Server is used here 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 the server receives the URL request whether it is a POST request or a GET request. That is to add a hidden variable to the form. When processing the request, we use the isset function to detect whether this hidden variable is set, thereby determining whether the request uses the POST or GET method.

http://www.bkjia.com/PHPjc/319167.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319167.htmlTechArticleIn most cases we specify another URL address to process the form content to the Action attribute, but there are also some cases You need to submit the form data to yourself. At this time we should...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn