Use PHP in the same form to process multiple submitted tasks

Source: Internet
Author: User
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. This simplicity makes it easy to handle more complex form events.

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. This simplicity 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 do I apply multiple submit tasks?

Before replying to this title, let me reply to a very clear title: Since many forms are more suitable for a single submit button, why do people sometimes need two (or more)?

The best way to describe this title is to use an instance in my recent development project. In this project, my task is to create a directory query system for a library. The book title is stored in the database, and the administrator can use a browser-based interface to view the records of any of the books, then, we choose to fulfill one of the four types of controls on this record: Member book return registration, member book borrowing 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. Data uploaded to the form will be processed in different ways, depending on the button to be clicked (borrowing/returning books and member records are associated; loss/sales records are changed to a specific 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 form processing code segment that implements active response of different buttons.

First, let me list a simple example: a form that submits a button. In this way, you can understand the basic concepts and lay a foundation for the complex model to be described. 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 ()
{
Echo 'You entered the number '.;}

?>

When a form is submitted to a PHP script, PHP automatically creates a specific

It is particularly important to note how to handle the button for submitting tasks in the above script. When the form is submitted, the submit button is changed

Print_r (Array );

To understand the above PHP scripts, you can view the internal structure of the array and clearly see the mutual connection between different body controls.

Contact Us

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: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.