Problem: I have a CRED Create User form that includes the first_name field. I would like to prevent Users from submitting an email address in this field.
Solution: The only way to implement this type of validation is to use PHP code on the backend and the cred_form_validate API. Then you could set up a custom regex or other string validation system to test the first name entered and return an error if necessary. Here's a simple example using the validation API to test the first name value:
add_filter('cred_form_validate','no_email_name_validation',10,2); function no_email_name_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']==12345) { //check first name value if ($fields['wpcf-first_name']['value']!='John') { //set error message for my_field $errors['wpcf-first_name']='Only members named John are allowed''; } } //return result return array($fields,$errors); }
Replace 12345 with the numeric ID of your CRED user form, and modify the conditional using your own custom validation code.
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate
https://stackoverflow.com/questions/12026842/how-to-validate-an-email-address-in-php
Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 1 reply, has 2 voices.
Last updated by 6 years, 11 months ago.
Assisted by: Christian Cox.
The forum ‘Types Community Support’ is closed to new topics and replies.