Processing form data in PHP is easier than other Web programming languages-if you use this language for a period of time, you will find this to be an indisputable fact. The simplicity of this operation makes it easy to handle more complex form events, including the topic discussed today, where multiple buttons are used to handle different tasks in the same form.
Why use multiple submission tasks?
Before I answer this question, let me answer a very obvious question: since many forms are more suitable for a single submit button, why do people sometimes need two (or more) commit buttons?
The best way to explain this is to use one of the examples from my recent development project to illustrate this problem. In this project, my task is to set up a detailed directory query system for a library. The title of the book is stored in the database, and the administrator will be able to use a browser-based interface to view the records of any one of these books, and then choose to perform one of four actions on this record: Member book registration, Member library registration, books lost records and book sales records.
All of the above tasks are handled by a separate form, which requires a corresponding button to respond to these tasks. The data that is passed into the form will be processed differently depending on which button is clicked (the borrowing/returning and member records are interrelated; The lost/sold record changes the detailed table of contents). Because a form can handle only one unique task, the same PHP script can handle four of these tasks based on the button being clicked and executing the appropriate code snippet. Therefore, you need to process a single form with multiple submit task buttons and a form processing code snippet that implements the automatic response of different buttons.
I'll start by listing a simple example: a form that submits a button. This gives you a clear understanding of the basic concepts and lays the groundwork for the complex paradigm to be told. Here is a form:
Single-button form
The following is the processor.php script that invokes the Submit task:
Check for submission
Retrieve value from posted data
if ($_post[' submit '))
{
echo "You entered the number". $_post[' number ']; }
?>
When a form is submitted to a PHP script, PHP automatically creates a specific $_post or $_get array, depending on the submission method used (I assume post for this article). The values that you type into the input field of the form automatically convert the key data in the array, and you can use the regular data symbols to access the data.
In particular, how to handle the push-button of a submit task in the above script is important. When the form is submitted, the Submit button is converted to an element in $_post according to its actual "name". Adding the following line of code is clear:
Print_r ($_post);
To understand the above PHP script, you can see the internal structure of the array, and you can clearly see the relationships between the different form controls.
http://www.bkjia.com/PHPjc/314447.html www.bkjia.com true http://www.bkjia.com/PHPjc/314447.html techarticle processing form data in PHP is easier than other Web programming languages-if you use this language for a period of time, you will find this to be an indisputable fact. This operation of the Jane ...