Viewing 4 replies - 1 through 4 (of 4 total)
  • Hello,

    All the additional fields are passed with all the prerequisites validations. If you need custom validation or validation for your customly created field, you can use this action hook user_registration_validate_{field_key}. For example the following codes will validate the number below 10.

    function ur_validate_number( $field, $form_data, $filter_hook, $form_id ) {
        $field_label          = isset( $form_data->label ) ? $form_data->label : '';
        $value                = isset( $form_data->value ) ? $form_data->value : '';
    
        if( $value < 10 ) {
    	add_filter( $filter_hook, function ( $msg ) use ( $field_label ) {
    		return __( $field_label . ' must be greater than 10.', 'user-registration' );
    	});
         }
    }
    add_action( 'user_registration_validate_number', 'ur_validate_number', 10, 4 );
    Thread Starter raquelfernandes

    (@raquelfernandes)

    Thank you very much!!

    Thread Starter raquelfernandes

    (@raquelfernandes)

    Hello,
    I ran tests by replacing the number with the id of the “user_registration_validate_number” -> “user_registration_validate_input_box_1551445019” field, but I was not successful.
    {Field_key} is the field id?

    Hello,

    You have to use field_key. Field_Key is not field_id. The field_key for input is text.
    Use like this user_registration_validate_text.

    Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Validate an additional field’ is closed to new replies.