How to submit a form to itself in PHP

巴扎黑
Release: 2016-11-10 10:24:55
Original
1177 people have browsed it

Using PHP for web development, the use of forms can be seen everywhere. Using its attributes Action and Method, you can specify the URL to which the content of the form is to be sent for processing and how to send the form data to the server. 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?

<?php
if(isset($_POST[&#39;action&#39;])&&$_POST[&#39;action&#39;]==&#39;submitted&#39;){
print&#39;<pre class="brush:php;toolbar:false">&#39;;
print_r($_POST);
print&#39;<ahref="&#39;.$_SERVER[&#39;PHP_SELF&#39;].&#39;">Pleasetryagain</a>&#39;;
print&#39;
Copy after login
'; }else{ ?> "method="POST"> Name:
Email:
Beer:
Warthog Guinness

The above code implements submitting the form to yourself (Note: In versions prior to PHP 4.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.


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template