I am looking to set-up a form that has a drop down menu at the top and this decides upon the form. What I am looking to do is have 2 forms (book us, contact us) which both have required form parts and both have Captcha, however I want diffrent fields to be reqired on each one - or each form to show diffrent fields (ie I dont want to know an address if contacting, but will if booking)
Any ideas how to do this?
PHP form
Moderator: General Moderators
Re: PHP form
The easiest thing to do would be to use JavaScript. Create two HTML forms and put them in two divs, like so:
Then in the HEAD section of the page, add this:
Just so you know that's possibly not the best way of doing it but for your purposes it should do nicely. I haven't checked the syntax or that it works though.
Edit: I tested it. It works perfectly.
Code: Select all
<select name="form_options" id="form_options" onchange="javascript: showForm()">
<option value="booking">Booking</option>
<option value="contact">Contact</option>
</select>
<div id="contact_form" style="display: none;">
<!-- Put form html here -->
</div>
<div id="booking_form" style="display: none;">
<!-- Put form html here -->
</div>
Code: Select all
<script type="text/javascript">
function showForm() {
var selectedForm = document.getElementById("form_options").options[document.getElementById("form_options").selectedIndex].value;
if(selectedForm == "booking") {
document.getElementById("contact_form").style.display = "none";
document.getElementById("booking_form").style.display = "block";
} else {
document.getElementById("contact_form").style.display = "block";
document.getElementById("booking_form").style.display = "none";
}
}
</script>
Edit: I tested it. It works perfectly.
Re: PHP form
Thanks so much for that.