script part:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
$(document).ready(function() {
$('#otherT').click(function() {
var $this = $(this);
if ($this.is(':checked')) {
$('#othertext').show();
} else {
$('#othertext').hide();
}
});
});
function check() {
if ($("#business").val() == "" || $("#fullname").val() == "" || $("#email").val() == "" || $("#phone").val() == "") {
alert("Fill up the form propperly.");
return false;
} else {
alert("Proceed...");
return true;
}
}
Form part:
<form method="post" action="formAction.php" onsubmit="return check();">
<label>Business Name <span style="font-weight: normal; font-style: italic;">(required)</span></label>
<input type="text" id="business" name="business"/>
<label>Full Name <span style="font-weight: normal; font-style: italic;">(required)</span></label>
<input type="text" id="fullname" name="fullname"/>
<label>Email Address <span style="font-weight: normal; font-style: italic;">(required)</span></label>
<input type="email" id="email" name="email"/>
<label>Phone Number <span style="font-weight: normal; font-style: italic;">(required)</span></label>
<input type="number" id="phone" name="phone"/>
<label>What is Your Enquiry about? <span style="font-weight: normal; font-style: italic;">(required)</span></label>
<label>Select as many as you like</label>
<input type="checkbox" name="enquiry" value="website" />
Free website/content audit
<input type="checkbox" name="enquiry" value="social" />
Free social media audit
<input type="checkbox" name="enquiry" value="seopackages" />
SEO Packages
<input type="checkbox" name="enquiry" value="adwords" />
Google AdWords
<input type="checkbox" name="enquiry" value="googleplus" />
Google+ Local Optimisation
<input id="otherT" type="checkbox" name="enquiry" value="other" />
Other
<input id="othertext" style="display: none;" type="text" name="enquiry" />
<input type="submit" value="Submit" name="submit"/>
formAction.php
if (isset($_POST['submit'])) {
$business = $_POST['business'];
$fullname = $_POST['fullname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$enquiry = is_array($_POST['enquiry']);
echo "bus: ".$business." fullname: ".$fullname." email: ". $email. " phone: ".$phone;
}
I have seen several post, but didn't understand, how i can collect the value from the checkbox. There is an extra option. when the user will click other, an extra textbox will appear to collect the value.
answer:
- added [] beside enquiry in the form
- changed the formAction.php into: http://pastebin.com/09DWFpfu