Welcome to WebmasterWorld Guest from 54.147.44.93

Forum Moderators: incrediBILL

Message Too Old, No Replies

Two submit buttons.

Form input submit choice.

     

smokeyb

9:05 pm on May 16, 2009 (gmt 0)

10+ Year Member



This may sound stupid but what's new?

Is is viable or even possible to have 2 buttons using the same form input? It is for a paypal cart and rather than duplicating the form options for both the Add to cart and Buy Now buttons, I'd like to have both buttons use the same form.

Is it possible

Thanks

dreamcatcher

3:19 pm on May 18, 2009 (gmt 0)

WebmasterWorld Senior Member dreamcatcher is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Ideally you give each button a unique name. When the form is submitted the button that is clicked is a part of the post array. The one that isn`t clicked isn`t.

<input type="submit" value="Submit One" name="first" />
<input type="submit" value="Submit Two" name="second" />

if (isset($_POST['first'])) {
// do something..
}

if (isset($_POST['second'])) {
// do something..
}

Hope that helps. You might need to juggle some code around as well.

dc

johnnie

1:42 am on May 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have you considered using a radio button to make the customer select? Then you can use some simple code to re-direct him or her based on the radio button status.

smokeyb

10:36 pm on May 22, 2009 (gmt 0)

10+ Year Member



Thanks for the help guys. I know that having the 2 submit buttons seems obvious but I just had the feeling it wasn't right (my knowledge of these things is the opposite to "extensive"), and I had played with the idea of dupicating the form for each action, but hiding the usused form somehow. I'll play around with both the suggestions and it is no real big if I have to opt for duplicate forms - it just looks prettier the way I want it.

Thanks

rocknbil

4:17 pm on May 23, 2009 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Ideally you give each button a unique name.

While a unique ID is generally useful for DOM and Javascript referencing, a unique name is not required on input type="submit." It will work just like a radio button unless your browser is doing something funky. Try it.

<input type="submit" value="Submit One" name="SubmitButton">
<input type="submit" value="Submit Two" name="SubmitButton">

if (isset($_POST['submitButton']) && ($_POST['submitButton']=='Submit One')) {
// action 1
}
else {
// action 2
}

 

Featured Threads

Hot Threads This Week

Hot Threads This Month