Use PHP in the same form to process multiple submitted tasks, processing form data in PHP is simpler than other web application languages-if you use this language for a while, you will find it an indisputable fact. The simplicity of this operation makes it easy to handle more complex forms "> <LINKhref =" http://www.php100.co
Processing form data in PHP is simpler than other web application languages-if you use this language for a while, you will find it an indisputable fact. The simplicity of this operation makes it easy to process more complex form events, including the topic discussed today, that is, there are multiple buttons in the same form to process different tasks.
Why use multiple submit tasks?
Before answering this question, let me answer a very clear question: Since many forms are more suitable for a single commit button, why do people sometimes need two (or more)?
The best way to explain this problem is to use an instance of my recent development project. In this project, my task is to create a detailed directory query system for a library. Book questions are stored in the database, and the administrator can use a browser-based interface to view the records of any one of the books, and then choose to perform one of the four operations on this record: member return registration, member borrow registration, book loss record and book sales record.
All the preceding tasks must be processed in an independent form, and corresponding buttons are required to respond to these tasks. The data passed into the form is processed in different ways, depending on the button to be clicked (borrow books/return books and member records are associated; lost/sale records change the detailed directory table ). Since a form can only process one unique task, the same PHP script can process the above four tasks based on the clicked button and the appropriate code segment. Therefore, you need to process a single form of multiple submit task buttons and a code segment for automatically responding to different buttons.
First, I would like to list a simple example: a form that submits a button. This allows you to clearly understand the basic concepts and lay the foundation for the complex examples to be presented. Here is a form:
Single-button form
The following is the processor. php script that calls 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 based on the submission method used (I assume POST in this article. Values in the input field of the form are automatically converted into key data in the array and can be accessed using regular data symbols.
It is particularly worth noting how to handle the button for submitting tasks in the above script. When the form is submitted, the submit button is converted to an element in $ _ POST based on your actual "name. It is clear to add the following line of code:
Print_r ($ _ POST );
To understand the above PHP script, you can view the internal structure of the array, and clearly see the relationship between controls of different forms.