One form data, various actions for two separate submit buttons

I have, in fact, a shopping basket, which should have two separate verification options. The first one removes the user from the site, but the form data must be published.

How to create two submit buttons that will send the same form data to their own separate page?

+3
source share
3 answers

If I understand correctly, you have two submit buttons on the same page, and both of them have the same shape, if so, this should do the trick.

if(isset($_POST['name1'])) {
//do stuff
}

if(isset($_POST['name2'])) {
//do other stuff
}
+6
source

Ok, you could do this: -

define your form with action = ""

then there are two buttons: -

<input type="button" value="button1" onClick="this.form.action='your_first_action_url'; this.form.submit()">
<input type="button" value="button2" onClick="this.form.action='your_second_action_url';this.form.submit()">
+6

You can set the onclick handler on the buttons and change the action of the form dynamically.
I give this answer because you have a javascript tag, and I assume that the external site receives the parameters via POST METHOD, so you cannot do the redirection in php

But I would not trust this because it requires users to have javascript ...

+2
source

Source: https://habr.com/ru/post/1720953/


All Articles