Custom Field has all the basic validation features such as required, min/max length.
If you want to add your own field validation, here is an example
Add a confirm email address field
- Add an Email Field from the settings & mark it as required.
- Take a note of its Unique ID or provide your own, for this example we are providing our own id which is "xoo_el_reg_email_again".
- When the user signs up, we need to check whether both the email fields value entered is same or not. If values are not same, we will add an error
- Add this code to your functions.php, I will explain it below.
//Validate confirm email address field
function xoo_cu_el_validate_registration_fields( $validation_error, $username, $password, $email ){
if( $_POST['xoo_el_reg_email'] !== $_POST['xoo_el_reg_email_again'] ){
$validation_error->add( 'email-match-error', "Emails don't match" );
}
return $validation_error;
}
add_filter( 'xoo_el_process_registration_errors', 'xoo_cu_el_validate_registration_fields', 10, 4 );
Code Explaination
-
$_POST['xoo_el_reg_email'] !== $_POST['xoo_el_reg_email_again']
Form values are stored in $_POST, you can grab any field value using $_POST[ $field_id ]
- We are checking if both the field values are equal or not.
If not equal, we're adding an error.
email-match-error is the error code.