I'm able to create a form that includes a single option checkbox, as the user is required to click the checkbox in order to submit the form, but I can't seem to get it to validate. Instead, the form is sent with or w/out the box being checked.
Here is the HTML code:
<li class="mainForm" id="fieldBox_100"><input class=mainForm type=checkbox name=field_100[] id=field_100_option_1 value="I agree" /><label class=formFieldOption for="field_100_option_1">I verify that the above information submitted is accurate.</label></li>
I noticed in the script that the 'validateField' function did not include: || fieldType == 'checkbox'
...so I added it to the script but it still didn't trigger validation.
I also tried setting: the last parameter below to '1', but it still didn't validate:
if (validateField('field_100','fieldBox_100','checkbox',1) == false)
retVal=false;
Lastly, I tried using the form as generated with the checkbox, but received the following error message:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
...for the second line below:
// Checkbox handling
$field_20_opts = $_POST['field_20'][0];
Can anyone help shed light on this?
TIA,
dbcom
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Validating checkboxes is not part of the current version. I can help but you will need to send me the link to your form number or send me the zip file in an email.
Your attempt to make it work was only partially implemented. This part was correct
if (validateField('field_100','fieldBox_100','checkbox',1) == false)
retVal=false;
but additional code needs to be added to the ValidateField function or a new function must be created to finish the modification. I did a similar change for someone else wanting to validate RadioButtons. Let me know if you would like me to help.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes, I would be interested. Tried sending the zip file to your SF account, but the zip and email was rejected by the server. Let me know how I might contact you alternatively.
Thanks,
dbcom
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have been trying to get this to work but I haven't been successful so far. Could anyone please help me out?
I have added:
if (validateCheckBox('field_14','fieldBox_14','checkbox',1) == false)
retVal=false;
if (validateField('field_14','fieldBox_14','checkbox',1) == false)
retVal=false;
I have done this before so I know what I have works. If you are still having trouble send me a zip of your form so I can debug what you have. If it's not just a simple tweak I can add in what I have done in the past and send it back to you.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm able to create a form that includes a single option checkbox, as the user is required to click the checkbox in order to submit the form, but I can't seem to get it to validate. Instead, the form is sent with or w/out the box being checked.
Here is the HTML code:
<li class="mainForm" id="fieldBox_100"><input class=mainForm type=checkbox name=field_100[] id=field_100_option_1 value="I agree" /><label class=formFieldOption for="field_100_option_1">I verify that the above information submitted is accurate.</label></li>
I noticed in the script that the 'validateField' function did not include: || fieldType == 'checkbox'
...so I added it to the script but it still didn't trigger validation.
I also tried setting: the last parameter below to '1', but it still didn't validate:
if (validateField('field_100','fieldBox_100','checkbox',1) == false)
retVal=false;
Lastly, I tried using the form as generated with the checkbox, but received the following error message:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
...for the second line below:
// Checkbox handling
$field_20_opts = $_POST['field_20'][0];
Can anyone help shed light on this?
TIA,
dbcom
Validating checkboxes is not part of the current version. I can help but you will need to send me the link to your form number or send me the zip file in an email.
Your attempt to make it work was only partially implemented. This part was correct
if (validateField('field_100','fieldBox_100','checkbox',1) == false)
retVal=false;
but additional code needs to be added to the ValidateField function or a new function must be created to finish the modification. I did a similar change for someone else wanting to validate RadioButtons. Let me know if you would like me to help.
Hi,
I have a problem with validating the check box as well.(They need to check and agree terms and conditions) I also put
if (validateField('field_100','fieldBox_100','checkbox',1) == false)
retVal=false;
inside my code however I understand that I still need to put some additional code inside ValidateField function.
would it be possible for you to help me as well? I have searched the forum for this code but I couldn't find it. I can email my files to you.
Thank you
Upper part of the form.html where Java functions are:
function validateCheckBox(fieldId, fieldBoxId, fieldType, required) {
if(fieldType == 'checkbox') {
fieldBox = document.getElementById(fieldBoxId);
if(required == 1) {
myfieldId = fieldId+"_option_1";
fieldObj = document.getElementById(myfieldId);
if(fieldObj.checked == 1) {
myfieldId = fieldId+"_option_1";
fieldObj = document.getElementById(myfieldId);
fieldObj.setAttribute("class","mainForm");
fieldObj.setAttribute("className","mainForm");
return true;
} else {
fieldObj.setAttribute("class","mainFormError");
fieldObj.setAttribute("className","mainFormError");
}
fieldObj.focus();
return false;
}
}
}
Lower part of form.html where validation occurs:
if (validateCheckBox('field_2','fieldBox_2','checkbox',1) == false)
retVal=false;
Thank you very much, everything works fine now....
Just for the future references; do I use the same code if I need to validate more than 1 check box in the same fieldBox?
Thanks again, phpFormGenerator is a great source!
Yes, I would be interested. Tried sending the zip file to your SF account, but the zip and email was rejected by the server. Let me know how I might contact you alternatively.
Thanks,
dbcom
Send an email without the attachment and I will reply with my email address.
I have been trying to get this to work but I haven't been successful so far. Could anyone please help me out?
I have added:
if (validateCheckBox('field_14','fieldBox_14','checkbox',1) == false)
retVal=false;
if (validateField('field_14','fieldBox_14','checkbox',1) == false)
retVal=false;
to the end of form.html, and:
function validateCheckBox(fieldId, fieldBoxId, fieldType, required)
{
if(fieldType == 'checkbox') {
fieldBox = document.getElementById(fieldBoxId);
if(required == 1) {
myfieldId = fieldId+"_option_1";
fieldObj = document.getElementById(myfieldId);
if(fieldObj.checked == 1) {
myfieldId = fieldId+"_option_1";
fieldObj = document.getElementById(myfieldId);
fieldObj.setAttribute("class","mainForm");
fieldObj.setAttribute("className","mainForm");
return true;
} else {
fieldObj.setAttribute("class","mainFormError");
fieldObj.setAttribute("className","mainFormError");
}
fieldObj.focus();
return false;
}
}
}
to the beginning of form.html.
This is the code for the checkbox:
<li class="mainForm" id="fieldBox_14">
<label class="formFieldQuestion">I accept the terms of this agreement *</label><span><input class=mainForm type=checkbox name=field_14[] id=field_14_option_1 value="yes" /><label class=formFieldOption for="field_14_option_1">yes</label></span></li>
It doesn't seem to work! Also: processor.php gives an error when you hit confirm:
Notice: Undefined index: field_14 in /my_domain/public_html/preorder/processor.php on line 15
Could someone please help me out? I'm so close but I just can't figure out what's going wrong here...
I have done this before so I know what I have works. If you are still having trouble send me a zip of your form so I can debug what you have. If it's not just a simple tweak I can add in what I have done in the past and send it back to you.
I managed to make it work. Turned out I pasted the javascript code one { too early. Yeah, that easily breaks things. Thanks for your time!!