Developer on Alibaba Coud: Build your first app with APIs, SDKs, and tutorials on the Alibaba Cloud. Read more ＞
Why use multiple submit tasks?
Before I answer this question, let me answer the obvious question: since many forms are more suitable for a single submit button, why do people sometimes need two (or more) of submit buttons?
The best way to explain this problem is to use an example from my recent development project. In this project, my task is to create a detailed catalogue query system for a library. Book titles are stored in the database, and administrators will be able to use a browser-based interface to view the records of any of these books, and then choose one of four actions on the record: Member book registration, Member library registration, books lost records and book sales records.
All of the above tasks are handled through a separate form, which requires the appropriate buttons to respond to these tasks. The data that is passed to the form will be processed in a different way depending on which button is clicked (the Library/return book and member records are interrelated; the loss/sales record changes the detailed catalog table). Because a form can only handle a single task, the same PHP script can handle the above four tasks based on the clicked button and executing the appropriate code snippet. Therefore, you need to handle a single form of multiple submit task buttons, and a form-handling code snippet that implements the automatic response of different buttons.
Let me start by enumerating 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 that will be described. Here is a form:
The following is the processor.php script that invokes the Submit task:
The following are the referenced contents:
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 in this article). The values you type into the form's input fields automatically convert the key data in the array, and you can use regular data symbols to access the data.
Notably, how to handle the push of a submit task in the above script. When a form is submitted, the Submit button is converted to an element in the $_post according to its actual "name". Adding the following line of code is clear:
To understand the above PHP script, you can look at the internal structure of the array, and you can see clearly how different forms of controls are interconnected.
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or
complaint, to email@example.com. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.
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:
and provide relevant evidence. A staff member will contact you within 5 working days.