htmlrich Posted April 20, 2010 Report Posted April 20, 2010 I have a vacation rental website. The owner wants in his contact form to be able to choose between his two properties or both when submitting an inquiry....Ok easy enough...I have set up checkboxes...When a viewer chooses either one it gets emailed to me perfectly...When the viewer chooses both properties (ie: puts checkmarks on both properties) only one of the properties gets listed in the email. here is the form http://www.myfloridabeachrentals.com/contactusrentals.html thanks in advance. Quote
newseed Posted April 20, 2010 Report Posted April 20, 2010 (edited) You have two indentical set of checkbox 'name'. <input type="checkbox" value="Coco Haven" name="property"> <input type="checkbox" value="Tropical Isles" name="property"> Give the first or second name a different name. You could do something like this: <input type="checkbox" value="Coco Haven" name="CocoHaven"> <input type="checkbox" value="Tropical Isles" name="TropicalIsles"> Edited April 20, 2010 by newseed Quote
htmlrich Posted April 20, 2010 Author Report Posted April 20, 2010 You have two indentical set of checkbox 'name'. <input type="checkbox" value="Coco Haven" name="property"> <input type="checkbox" value="Tropical Isles" name="property"> Give the first or second name a different name. You could do something like this: <input type="checkbox" value="Coco Haven" name="CocoHaven"> <input type="checkbox" value="Tropical Isles" name="TropicalIsles"> I'm kinda confused at to what to put in my HIDDEN fields at the bottom of the page. I need to make this checkbox required but if I do it your way, then both have to be checked to pass the form. I changed it to radio boxes and this works fine. Thanks for your help anyways... Quote
falkencreative Posted April 21, 2010 Report Posted April 21, 2010 I'm kinda confused at to what to put in my HIDDEN fields at the bottom of the page As long as you place the hidden fields within the <form> tags, you should be fine. Exactly where you place them within the <form> tags is a personal preference thing... I usually group them together and place them just below the opening <form>. In regards to checkboxes: I think radio boxes make more sense here, since it is a required value. However, you can group checkboxes together. If you assign each checkbox the same name with a "[]" on the end (for example "place[]") PHP will automatically gather those values into an array for you. Here's a quick example: <?php // when the form is submitted... if (isset($_POST["submit"])) { if (isset($_POST["place"])) { $place = $_POST["place"]; if (isset($place[0])) { echo $place[0] . "<br/>"; } if (isset($place[1])) { echo $place[1] . "<br/>"; } if (isset($place[2])) { echo $place[2] . "<br/>"; } /* alternately: foreach ($place as $p) { echo $p."<br />"; } */ } else { echo "nothing selected!"; } } ?> <form action="" method="post"> Please choose type of residence::<br /> Los Angeles:<input type="checkbox" value="la" name="place[]">:<br /> New York:<input type="checkbox" value="ny" name="place[]">:<br /> Sacramento:<input type="checkbox" value="sac" name="place[]">:<br /> <input type="submit" name="submit"> </form> In this case, I'm using the line if (isset($_POST["place"])) to make sure that at least one of the checkboxes has been selected. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.