On some sites it is necessary to add a checkbox option to accept terms and conditions or perhaps to vouch for your eligibility to complete the form (e.g. "I am over 18"). This is an easy way to add such a checkbox.
This hack is a variation on the previously written hack to make the contact form mailing list opt-in required. It involves creating an HTML snippet and adding some validation.
Please note:
1) This is a "fake" field. It is not recognised by the form processor and no data is stored. The field exists only for validation purposes.
2) JavaScript is required for the validation to work.
------------------------------------------
1) Add HTML snippet
Log into sc_admin and navigate to the contact form builder page.
Create a HTML snippet and position it in the form order as desired, and paste the following code into it:
<div class="lbl"><input type="checkbox" name="terms_accept" id="terms_accept" value="1" /> <label for="terms_accept">I have read and agree to the <a href="terms.html">terms and conditions</a></label></div>
Note that I have made the reference to terms and conditions in the label a link. You should amend this to point to your terms and add links for anything else needed (e.g. a privacy policy). Of course, if the purpose of this checkbox is to vouch for eligibility then links are probably not needed...
2) Validation
Open sc_admin/js/forms.js
Find the function validateContact() and the line of code inside it which says:
if ($("p.err").length > 0) { return false; }
Now add this block of code before that line:
if (!$("#terms_accept").is(":checked")) {
var mydiv = $("#terms_accept").parents("div")[0];
$(mydiv).after("<p class=\"err\"><em>Please accept the terms and conditions</em>");
}
You may want to edit the validation error message that is on the third line of the above code.
This completes the process. You should now have a required checkbox on your form.