View Full Version : 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.
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.
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/canada-car-rental.html
These values seem to vanish if the form is not submitted. Mahalo, erin :)
Medyman
04-04-2008, 03:52 AM
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.
djr33
04-04-2008, 04:48 AM
There is another way to do this.
Just add two different submit buttons on the page.
Now, there are two possible ways to continue:
//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!"; }
?>
//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!"; }
?>
I don't think hes looking for php.
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 :)
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)
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
Basic Insurance Only <input type="radio" name="insurance" value="Basic" checked="checked">
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 :)
I think I may have it working! This is the code I used:
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 :)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.