Problem:
How to stop the form from submitting unless a correct value is added and compared with a custom field
Solution:
- Add a generic field in the form.
- Use the cred_form_validate hook to check against the entered field and the custom field in question:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate
Add the custom code below according to the documentation:
<?php add_filter('cred_form_validate','chr_validation',10,2); function chr_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'] == FORMID) { //check my_field value if ($fields['generic-field']['value'] != types_render_field("custom-field", array()) ) { //set error message for my_field $errors['generic-field'] = 'Please enter a correct PIN.'; } } //return result return array($fields,$errors); }
Replace FORMID with the ID of your form.
Replace custom-field with the slug of the custom field that you want to check against.
Replace generic-field with the slug of the generic field option you added in the form.
Relevant Documentation:
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
This topic contains 13 replies, has 2 voices.
Last updated by 2 years, 6 months ago.
Assisted by: Christopher Amirian.