Validator Doc not working (FORMS API)
-
Hello, So i tried to implement a min and max number into a text field (info take from here: https://wpadverts.com/documentation/forms-api/).
I included in my wpadverts/includes/functions.php this codes:
add_filter( "adverts_form_load", "my_adverts_form_load" ); function my_adverts_form_load( $form ) { if( $form["name"] != "advert" ) { return $form; } $form["field"][] = array( "name" => "check", "type" => "adverts_field_text", "order" => 25, "label" => "Input a number between 10 and 100", "is_required" => true, "validator" => array( array( "name" => "in_between", "min" => 10, "max" => 100, )), "validator" => array( array( "name" => "is_required" ), ) ); return $form; } function in_between( $data, $params = null ) { if( isset( $params["min"] ) && $data < $params["min"] ) { return "to_small"; } if( isset( $params["max"] ) && $data > $params["max"] ) { return "to_big"; } return true; } adverts_form_add_validator("in_between", array( "callback" => "in_between", "label" => "In Between", "default_error" => __( "Incorrect value.", "adverts" ), "message" => array( "to_small" => "Value has to be greater than %min%.", "to_big" => "Value has to be smaller than %max%." ), "validate_empty" => false ));
However it’s not working. Whenever I insert a number outside of min-max, it continues like the limits do not exists. How can I change this?
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Validator Doc not working (FORMS API)’ is closed to new replies.