Table of Contents
This filter will help you add an extra validation for a custom field:
wppb_check_form_{field_type}
{field_type} can be one of the following:
Below is an example on how we can use this filter to add a Custom Validation for an Input Field Type
In this case since we use an Input Field Type, the filter name will be:
add_filter( ‘wppb_check_form_field_input’, ‘wppbc_custom_input_validation’, 20, 4);
This function will add a custom validation for an specific Input Field, with the meta name of “special_input”.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | /* * Custom Input Validation */ /* handle field validation */ add_filter( 'wppb_check_form_field_input', 'wppbc_custom_input_validation', 20, 4 ); function wppbc_custom_input_validation( $message, $field, $request_data, $form_location ){ if( $field['field'] == 'Input' && $field['meta-name'] == 'special_input' ){ if ( isset( $request_data[$field['meta-name']] ) && trim( $request_data[$field['meta-name']] ) != '' ){ $input = $request_data[$field['meta-name']]; $possible_values = array('one' ,'two', 'three', 'four', 'five'); if( !in_array( $input, $possible_values) ) { return 'You have entered an incorrect value for this field.'; } } if ( ( isset( $request_data[$field['meta-name']] ) && ( trim( $request_data[$field['meta-name']] ) == '' ) ) && ( $field['required'] == 'Yes' ) ){ return wppb_required_field_error($field["field-title"]); } } return $message; } |
Combine the power of Profile Builder with Paid Member Subscriptions to set up user registration, memberships, and recurring revenue.
Get 25% off with the bundle