I created a form and modified it.
I would like to add a required field. Where, and in which file(s) is this code located.
form.html
processor.php
install.php
John
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Validating a checkbox is more complex. You probably do not want to require every box be checked. You may or may not want 1 or more check boxes as required.
Most typically you would want to have a requirement that only one of many check boxes required. So depending on the number of boxes and the number of desired required boxes your form code would have to be custom. Since this level of customization would require many many many variations of code generation, it is left to the user to define and implement whatever customization they deem necessary.
You are correct, check boxes have no current validation checking feature to ensure that a check box selection is required. Look in the form.html file for the Java code that does form field requirements checking. This is what you will find.
I did not provide an example. I copied actual code from the form.html file. This code iscommon to every form and validates fields selected as "required". To make one of your check boxes required will require custom code.
If you are asking me if I can provide custom code for you the answer is yes I can but you will have to email me a link to your form and a copy of your processor.php file.
What you are looking for seems simple enough.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I created a form and modified it.
I would like to add a required field. Where, and in which file(s) is this code located.
form.html
processor.php
install.php
John
At the bottom of the form.html file you will find lines like this:
if (validateField('field_1','fieldBox_1','text',0)
One for each form entry. Changing the last ,0 to ,1 will change the field from not required to required.
What if it is a checkbox?
if (validateField('field_2','fieldBox_2','checkbox',1) == false)
This does not seem to work, it does not require a check in this fieldbox 2
Validating a checkbox is more complex. You probably do not want to require every box be checked. You may or may not want 1 or more check boxes as required.
Most typically you would want to have a requirement that only one of many check boxes required. So depending on the number of boxes and the number of desired required boxes your form code would have to be custom. Since this level of customization would require many many many variations of code generation, it is left to the user to define and implement whatever customization they deem necessary.
You are correct, check boxes have no current validation checking feature to ensure that a check box selection is required. Look in the form.html file for the Java code that does form field requirements checking. This is what you will find.
function validateField(fieldId, fieldBoxId, fieldType, required)
{
fieldBox = document.getElementById(fieldBoxId);
fieldObj = document.getElementById(fieldId);
if(fieldType == 'text' || fieldType == 'textarea' || fieldType == 'password' || fieldType == 'file' || fieldType == 'phone' || fieldType == 'website')
{
if(required == 1 && fieldObj.value == '')
{
fieldObj.setAttribute("class","mainFormError");
fieldObj.setAttribute("className","mainFormError");
fieldObj.focus();
return false;
}
}
else if(fieldType == 'menu' || fieldType == 'country' || fieldType == 'state')
{
if(required == 1 && fieldObj.selectedIndex == 0)
{
fieldObj.setAttribute("class","mainFormError");
fieldObj.setAttribute("className","mainFormError");
fieldObj.focus();
return false;
}
}
else if(fieldType == 'email')
{
if((required == 1 && fieldObj.value=='') || (fieldObj.value!='' && !validate_email(fieldObj.value)))
{
fieldObj.setAttribute("class","mainFormError");
fieldObj.setAttribute("className","mainFormError");
fieldObj.focus();
return false;
}
}
}
As you can see
fieldType == 'checkbox'
can not be found in this validation code.
There is only one checkbox that I need to require being checked.
"They agree to terms"
So do I just add || fieldType == 'checkbox' in the sixth line of your example? Or some where else as well?
Would a radio button be better? Yes or no answer, I don't see that "type=radio name" is an option either.
I did not provide an example. I copied actual code from the form.html file. This code iscommon to every form and validates fields selected as "required". To make one of your check boxes required will require custom code.
If you are asking me if I can provide custom code for you the answer is yes I can but you will have to email me a link to your form and a copy of your processor.php file.
What you are looking for seems simple enough.