homepage Welcome to WebmasterWorld Guest from 54.197.130.16
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / HTML
Forum Library, Charter, Moderators: incrediBILL

HTML Forum

    
Two submit buttons.
Form input submit choice.
smokeyb




msg:3915106
 9:05 pm on May 16, 2009 (gmt 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

 

dreamcatcher




msg:3915825
 3:19 pm on May 18, 2009 (gmt 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

johnnie




msg:3916878
 1:42 am on May 20, 2009 (gmt 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.

smokeyb




msg:3918817
 10:36 pm on May 22, 2009 (gmt 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

rocknbil




msg:3919079
 4:17 pm on May 23, 2009 (gmt 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
}

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / HTML
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved