Tell us what you are trying to do?
How do you make all fields “required”?
We have a form named Structural Systems that a user can use to inspect their home, we would like for all custom fields that don’t get selected or “inspected” to be required so that they are forced to pick one. This way something gets printed out when you see your inspection results after submitting.
Inspection form:
hidden link
What is the link to your site?
hidden link
You should have backend login credentials on file, please let me know if I need to provide them again.
Hi Philip,
Unfortunately i'm not able to see the form on the page.
However if you want to make the custom fields required then you can do it by going to Toolset -> Custom Fields and edit the field group that the custom fields belong to.
Once you've done that you can edit each of the custom fields and ensure that the required options are checked.
For those fields that cant be set as required you can use the hook below to create a custom validation function to force the field to be required.
https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate
Please let me know if this helps.
Thanks,
Shane
Hello Shane,
You will need login credentials to be able to view the form. Do you still have access to the backend? Christian was the former Support specialist that would help us out. Not sure if that will help?
Hi Philip,
I may not need the credentials at this stage as my instructions in the previous response should be able to assist you with getting your fields to be required.
If there are any issues with this please let me know.
Thanks,
Shane
Hello Shane,
We have looked into this and we still need your help. We are using the "checkboxes" custom field and we need the user to be forced to pick "inspected" or "not inspected" on all items. (Screenshot attached)
If at all possible, please log in and take a closer look. Your help is greatly appreciated.
Hi Philip,
Yes please provide me with admin access to the site and a link to the form page.
For this field it will require our validation hook to make it required.
I've enabled the private field for your next response.
Thanks,
Shane
Hi Philip,
Thankyou for the credentials.
I've added the following code to Toolset -> Settings -> Custom Code.
// Put the code of your snippet below this comment.
add_filter('cred_form_validate','my_validation',10,2);
function my_validation($error_fields, $form_data)
{
//field data are field values and errors
list($fields,$errors)=$error_fields;
//uncomment this if you want to print the field values
//print_r($fields);
//validate if specific form
if ($form_data['id']==331)
{
//check if the user selected a Grading and Drainage value
if (empty($fields['wpcf-grading-and-drainage']['value']))
{
//set error message for Grading and Drainage
$errors['grading-and-drainage'] = 'No value selected';
}
}
//return result
return array($fields,$errors);
}
You form should now be checking if the user selects the field option.
Thanks,
Shane
My issue is resolved now. Thank you!