Jump to content

Checkboxes


htmlrich

Recommended Posts

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.

Link to comment
Share on other sites

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 by newseed
Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...