Multiple HTML Forms on One Page

前端 未结 5 991
一整个雨季
一整个雨季 2021-01-05 04:21

If I have multiple HTML tags with separate submit forms, how do I know which when was posted in the PHP file that processes the form\'s data?

5条回答
  •  渐次进展
    2021-01-05 04:49

    This works for me....

    1. Each form has a unique 'name'...

      form method="post" action="" name="uniqueName" id= "uniqueName"

    2. Each form has this hidden field...

      input type="hidden" id="action1_1" name="action1" value="1"

    with unique id extension ( _1, _2, 3 ... and unique value (1,2,3,....) and common name: action1

    1. then in the php index script :

      $action1 = $_POST['action1'];

      if ( $action1 == "1" ) { include("form_process1.php"; //...do whatever that form need dones... } else if ( $action1 == "whateverelse" ) { include("form_process.php"; // ...do whatever that form does... }

提交回复
热议问题