简体   繁体   中英

Submitting two different forms from a single submit button in PHP?

如何在使用PHP单击第二个表单的提交按钮后,在同一个数据库中的两个不同表中提交两个不同的表单dat,每个表单都有一个提交按钮?

Create the a number of hidden fields in the second form (depending on how many textfields you have in the first one). On the second submit buttone use onclick="return xxx()" where xxx is a function that sets the hidden fields in the second form with the values from the first one. Just remember to return bool from xxx().

PHP runs on the server side and (usually) renders HTML before the user has a chance to interact with it. You can't, as far as I know, connect a single button to two forms with only HTML, hence you can't do it with only PHP. You'll have to use JavaScript, for instance you could use jQuery to intercept the submit event and do whatever you want to do instead of letting the form submit a request as usual.

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