简体   繁体   中英

Distinguishing submit buttons in separate forms with PHP

If one has multiple input forms, is there a way for one to distinguish one submit button from the other? The reason is I have two forms and each form performs a different task.

Both forms do a submit and each submit will perform an SQL query. The first one is a SELECT FROM query to do a search for data and the second will do UPDATE or DELETE (using this code on two different pages) query.

There might be many cases
First: if all the forms have the same action attribute then you will have to name the submit buttons differently.
second: If the forms have different actions then there is no need to name the buttons differently. You can achieve the task with the same name.
Three: if you want some of the fileds to have a different form action in your form then you can try this

<form action="demo_form.asp">
  First name: <input type="text" name="fname"><br>
  Last name: <input type="text" name="lname"><br>
  <input type="submit" value="Submit"><br>
  <input type="submit" formaction="demo_admin.asp"
  value="Submit as admin">
</form> 

To learn about form action overriding click here

  • Give each form a hidden input with a unique name.
  • Give the submit buttons different names

you specify the <input type="submit" name="form1" />

that name part is the way to specify seperately to php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM