Results 1 to 9 of 9

Thread: Input Form with 2 Submit Buttons

  1. #1
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default Input Form with 2 Submit Buttons

    Is it possible to have a form on a web page that has 2 submit buttons that each perform a different action depending on which one you click?

    For example, a car rental form where people enter the dates and car type they want, and then click one button if they want insurance and one button for no insurance. The data entered is used in both cases, but they get sent to different pages depending on the button they click. I tried using a separate link if they want insurance, but then the data entered in the form was not transferred to the result page. Would really appreciate some help. Thanks.

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Why don't you have just a drop-down, that'll be an onChange, so if you change it to insurance then below will be an insurance form, but if its something else, then its something else.
    Jeremy | jfein.net

  3. The Following User Says Thank You to Nile For This Useful Post:

    kuau (04-04-2008)

  4. #3
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default

    Dear Nile: This sounds interesting but I'm not sure I follow the javascript. Do you mean add a drop-down within the form itself? Here is the form I'm talking about and I need to preserve the values that are entered into the form whether they want insurance or not.

    http://www.carrentalhawaii.com/html/...ar-rental.html

    These values seem to vanish if the form is not submitted. Mahalo, erin

  5. #4
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Hi Erin...

    This is how I would do it:

    Keep your form as is.
    Add radio buttons for insurance -- yes and no.

    Then in your php processing test to see what the value is. If it's yes, send them to one place...if it's no send them to another. You could also do the same with a checkbox (see if the value is set or not and redirect as needed).

    I think that'll be easier than mucking around with javascript and two submits and all that.

  6. The Following User Says Thank You to Medyman For This Useful Post:

    kuau (04-04-2008)

  7. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    There is another way to do this.

    Just add two different submit buttons on the page.

    Now, there are two possible ways to continue:
    Code:
    //html form:
    <input type="submit" name="SUBMIT1" value="submit">
    <input type="submit" name="SUBMIT2" value="submit">
    
    //php receiving page:
    <?php
    if (isset($_POST['SUBMIT1'])) { echo "Submit1 was clicked, not S2."; }
    else { echo "Ok, S1 was not pushed. It must have been S2!"; }
    ?>
    Code:
    //html form:
    <input type="submit" name="submit" value="YES">
    <input type="submit" name="submit" value="NO">
    
    //php receiving page:
    <?php
    if ($_POST['submit']=='YES') { echo "The submit value is YES!"; }
    else { echo "Submit value is not yes. It must be NO!"; }
    ?>
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. The Following User Says Thank You to djr33 For This Useful Post:

    kuau (04-04-2008)

  9. #6
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    I don't think hes looking for php.
    Jeremy | jfein.net

  10. #7
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default

    Hey, Nile, where did your javascript go? I just got back and was going to try it but alas, it is gone. (?) Hmmm.

    Anyway, I'll try the other ways and see if I can get something to work. Logically they make sense to me. Because the changes are to a template that gets used on several pages, is it possible to add a section conditionally such that it shows up only in certain cases? For example, if country=Canada then add a choice of insurance; otherwise, don't. Thank you, Medyman and Daniel, for the great suggestions! erin

  11. #8
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default

    Dear Daniel & Medyman:

    I used both your methods combined and it works!! Thanks so much. But I ran into a glitch. Only people from Canada & Commonwealth countries get the insurance deal so I have created "home" pages & result pages for both. Only these special home pages have the radio buttons for additional insurance. So if someone clicks Canada in the side menu it goes to the Canada homepage and all is well. But if they use the form on the regular home page and put Canada as "Country of Residence" it takes them to the Canada result page, totally bypassing the page where they choose insurance. SO I wrote this code hoping it would check to see if they were coming from the regular page or the Canada home page, but it doesn't work... (the bottom one works but not the top)

    Code:
    if ($_POST['Country'] == "CA") {
      if (isset($_POST['insurance'])) { 
        if ($_POST['insurance'] == "Additional") { 
    	include ($canada); 
    	exit;
        } 
      } else { 
           include ($canada-home);
           exit;
      }
    }
    
    if ($_POST['Country'] == "CW") {
      if ($_POST['insurance'] == "Additional") { 
        include ($commonwealth);
        exit;
      } 
    }
    //html file

    Code:
    Basic Insurance Only <input type="radio" name="insurance" value="Basic" checked="checked">&nbsp; &nbsp;
    Additional Insurance Deal <input type="radio" name="insurance" value="Additional">
    The error is live right now here: http://www.carrentalhawaii.com/index.html
    so I kinda need to fix it quickly.

    I'm just guessing at how to tell what page they came from. Any ideas? Thanks, erin

  12. #9
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default

    I think I may have it working! This is the code I used:

    Code:
    if ($_POST['Country'] == "CA") 
    {
      if ($_POST['insurance'] == "Additional") 
      { 
          include ($result_canada); 
          exit;
      } 
      if ($_POST['insurance'] != "Basic" AND $_POST['insurance'] != "Additional") 
     { 
        include ($home_canada); 
        exit;
      } 
    }
    I'm sure there is a more elegant way to do it but I need to go outside now. Thanks for helping me! erin

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •