Welcome to WebmasterWorld Guest from 54.196.244.186

Forum Moderators: incrediBILL

Message Too Old, No Replies

Two submit buttons.

Form input submit choice.

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

Full Member from GB 

10+ Year Member

joined:May 20, 2003
posts:272
votes: 0


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

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

Senior Member

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

joined:Mar 30, 2003
posts:3719
votes: 0


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

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Aug 17, 2004
posts:1354
votes: 0


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.
10:36 pm on May 22, 2009 (gmt 0)

Full Member from GB 

10+ Year Member

joined:May 20, 2003
posts:272
votes: 0


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

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

Senior Member

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

joined:Nov 28, 2004
posts:7999
votes: 0


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
}

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members