checkbox in form

hi all newbie here

i have a contact form working nicely except the checkboxes.

any help is very appreciated :slight_smile:

the html:

<form id="contact" method="post" action="">
<fieldset>	

<label for="name">Name</label>
<input type="text" name="name" placeholder="Full Name" title="Enter your name" class="required">

<label for="phone">Contact numbers</label>
<input type="tel" name="phone" placeholder="ex. (5555) 555-555">

<label for="email">E-mail</label>
<input type="email" name="email" placeholder="[email protected]" title="Enter your e-mail address" class="required email">

<label for="besttime">Best time to contact me</label>
<input type="text" name="besttime" placeholder="morning/afternoon/evening">

<label for="postcode">Post code of property to be surveyed</label>
<input type="text" name="postcode" placeholder="">

<label for="propertytype">Type of property</label>
<input type="text" name="propertytype" placeholder="house/flat">

<label for="bedrooms">Number of bedrooms</label>
<input type="number" name="bedrooms" placeholder="1,2,3,4,5,6,etc">

<label for="enquiry">Nature of enquiry</label>
<textarea name="enquiry"></textarea>

<h4>Services required</h4>

<input type="checkbox" name="services" value="onsiteadvice" /> Onsite advice<br />
<input type="checkbox" name="services" value="fullsurvey" /> Full survey &amp; written report<br />
<input type="checkbox" name="services" value="data" /> Data logging service<br />
<input type="checkbox" name="services" value="mouldcontrol" /> Mould control / products<br />
<input type="checkbox" name="services" value="productinformation" /> Product information from site<br />
<input type="checkbox" name="services" value="ventilation" /> Ventilation advice<br />
<input type="checkbox" name="services" value="mouldswabs" /> Mould swabs<br />
<input type="checkbox" name="services" value="notsure" /> Not sure



<label for="message">Any other information</label>
<textarea name="message"></textarea>

<input type="submit" name="submit" class="button" id="submit" value="Send Message" />

</fieldset>
</form>

here’s the process.php file:

[php]

<?php // Get Data $name = strip_tags($_POST['name']); $phone = strip_tags($_POST['phone']); $email = strip_tags($_POST['email']); $besttime = strip_tags($_POST['besttime']); $postcode = strip_tags($_POST['postcode']); $propertytype = strip_tags($_POST['propertytype']); $bedrooms = strip_tags($_POST['bedrooms']); $enquiry = strip_tags($_POST['enquiry']); $onsiteadvice = strip_tags($_POST['services']); $fullsurvey = strip_tags($_POST['services']); $data = strip_tags($_POST['services']); $mouldcontrol = strip_tags($_POST['services']); $productinformation = strip_tags($_POST['services']); $ventilation = strip_tags($_POST['services']); $mouldswabs = strip_tags($_POST['services']); $notsure = strip_tags($_POST['services']); $message = strip_tags($_POST['message']); // Send Message mail( "[email protected]", "Contact Form", "Name: $name\nPhone: $phone\nEmail: $email\nBestime: $besttime\nPostcode: $postcode\nPropertytype: $propertytype\nBedrooms: $bedrooms\nEnquiry: $enquiry\nServices: $onsiteadvice\nFullsurvey: $services\nData: $services\nMouldcontrol: $services\nProductinformation: $services\nVentilation: $services\nMouldswabs: $services\nNotsure: $services\nMessage: $message\n", "From: Forms " ); ?>

[/php]

You need to tell your php script that you have an array of checkboxes in your html form. Here is how to do this:

<input type="checkbox" name="services[]" value="onsiteadvice" /> Onsite advice<br /> <input type="checkbox" name="services[]" value="fullsurvey" /> Full survey &amp; written report<br /> <input type="checkbox" name="services[]" value="data" /> Data logging service<br /> <input type="checkbox" name="services[]" value="mouldcontrol" /> Mould control / products<br /> <input type="checkbox" name="services[]" value="productinformation" /> Product information from site<br /> <input type="checkbox" name="services[]" value="ventilation" /> Ventilation advice<br /> <input type="checkbox" name="services[]" value="mouldswabs" /> Mould swabs<br /> <input type="checkbox" name="services[]" value="notsure" /> Not sure

Then, in your php code you can process array of checked checkboxes:
[php]$data = implode(", ",$_POST[ā€˜services’]);[/php]

thank you sooooo much for your help and quick reply :slight_smile: it worked a treat :slight_smile: :slight_smile:

ps: it seems to have blown the form sent notice.

once again any help very appreciated

this is the code in the head:

[code]

[/code]

You have this line, where you’re hiding the #contact element, and after that you’re appending the ā€œthanksā€ message - it will not display.

$('#contact').hide(); $('#contact').append("<p class='thanks'>Thanks! Your request has been sent.</p>")

You need to add some other elelement that remains visible and append this message to it.

thats it! very big thanks again :slight_smile: :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service