Advanced Form Validation

Form validation is the process when users enter data, and the browser and/or the web server will check to see that the data is in the correct format and within the constraints set by the program. To the JetFormBuilder form, you can apply the Default (browser) or Advanced validation.

The Advanced option has such advantages compared to the Default (browser) option:

  • Editing or translating the error text;
  • Customizing the appearance;
  • Custom validation rules;
  • Server-Side validation;
  • Validate non-basic inputs.

Advanced Form Validation

If you want to add validation to the WordPress form, proceed to the Validation menu section in the Form settings tab. Unfold it, and you’ll see such settings:

validation menu section
  • Enable form safety. This option is used when there are form caching or conflict issues. It protects the form with a WordPress nonce. Toggle this option off if the form page’s caching can’t be disabled;
  • Enable csrf protection. If enabled, it protects a form from the attacks that force authenticated users to submit a request to a website against which they are currently authenticated;
  • Variation type. Here, you can pick two options:
    • Default. Native validation that works by browser;
advanced validation type
  • Advanced. If you select this option, you can click the “Edit validation messages” button, and you’ll see the “Edit Manual Options” pop-up, where you can change the error text for different field types:
edit manual options
  • Field is empty. For all field types if the Is Required option is enabled for the specified field. Will be shown if users don’t fill in the Required field and click the “Submit” button;
  • Email is not valid. For the Text Field with the selected “Email” Field Type in the Field Settings menu section for the block. The message will be shown if users enter an incorrect email address;
  • URL is not valid. For the Text Field with the selected “Url” Field Type in the Field Settings menu section for the block. Will be shown if users enter an incorrect web address;
  • Input mask is not completed. For the Text Field with the selected “Tel” Field Type, the enabled Set Input Mask toggle and the filled Input mask field in the Field Settings menu section for the block. It will be shown if users enter their phone number incorrectly according to the Input mask field settings and click the “Submit” button;
file size limit exceeded
  • Files limit exceeded. For the Media Field with the Maximum allowed files to upload field filled. For example, if you set “3,” the error message will be shown if users try to upload four files or more;
  • File size limit exceeded. For the Media Field with the Maximum size in MB field filled. For example, if you set “1” Maximum size in MB, the notification will be “The size of this file cannot exceed 1 MB” if users upload a file whose size is bigger than 1 MB;
  • File type is not included in the allowed types list. For the Media Field with the Allow mime types field filled. For example, if you set the “gif/image” option, the error message will be shown if users try to upload files of other types;
  • Value does not reach the minimum. For the Number Field and Range Field with the Min value field filled. For example, if you set “5,” the error message will be shown if users try to enter or set a number less than “5”;
value exceeds the maximum
  • Value exceeds the maximum. For the Number Field and Range Field with the Max value field filled. For example, if you set “100,” the error message will be shown if users try to enter or set a number greater than “100”;
  • Not enough characters. For the Text Field and Textarea Field with the Min length (symbols) field filled. For example, if you set “5,” the error message will be shown if users try to enter less than five symbols;
  • Character limit exceeded. For the Text Field and Textarea Field with the Max length (symbols) field filled. This message may occur if you set the Value option and the value exceeds the limit. For example, you created a post editing form and added the Text Field for the post title. In the Value section, you set it so that the field shows the current post title, and if it exceeds the limit, the error message will occur if you click the “Submit” button, so you will need to edit the title to submit the form;
timestamp is too early
  • Timestamp is too early. For the Date Field, Datetime Field, and Time Field with the Starting from time/date fields filled. For example, if you set “8:00,” in the Starting from time field, the error message will be shown if users try to set the time that is earlier than 8 a.m.;
  • Timestamp is too late. For the Date Field, Datetime Field, and Time Field with the Limit time/dates to fields filled. For example, if you set “17:00,” in the Starting from time field, the error message will be shown if users try to set the time that is later than 5 p.m.

Advanced Form Validation for Separate Blocks

In addition to the advanced form validation, you can set the Validation for separate form fields in the Block settings tab. This option is available for the Text Field, Textarea Field, Media Field, Number Field, Range Field, Date Field, Datetime Field, and Time Field blocks. You can select such Validation Types:

Inherit

If you select this option, validation is inherited from the form arguments. Here, you can only add advanced rules that check the entered data in the Text Field and Textarea Field blocks, and if the data does not match the rule, the error message will appear.

inherit validation for blocks in a form

Hover over the message in the blue rectangle and press the “+ Add Rule” button.

In the Rule Type drop-down menu, you can select such types:

rule type
  • Equals. Displays the error message if the rule’s condition doesn’t match the data users enter into the form. In the Choose Field drop-down menu, you can select one of the form fields or set “Custom value.” If you pick the “Custom value” option, the Symbols field will appear, where you can enter symbols that must be typed in the form field. If you hit the coin-stack-shaped button near the Symbols field, you can set the Preset settings for this field. Also, if you push the wrench-shaped button, you can use macros with the form field names. In the Error Message field, you can set the custom error message.
equals rule type

For example, you have two text fields: “Password” and “Confirm Password.” Click on the “Confirm Password” Text Field and hit the “Edit Advanced Rules” button. In the Edit Advanced Rules pop-up, pick the “Equals” Rule Type, select the “Password” Text Field in the Choose field, and set the custom Error Message. So the error message will appear when the text in the “Password” and “Confirm Password” fields doesn’t match.

advanced rule example
  • Must contain characters. The message will appear when users don’t enter the required characters, for example, “@” for the email field;
must contain characters rule
  • Must not contain characters. The message will appear when users enter the restricted characters;
  • Matches regular expressions. The message will appear if users enter the symbols combination that does not match the regular expressions. For example, you can set the “^.{6,}$” Regular expression for the Text Field with the “Password” Field Type, and the custom ErrorMessage “The password is too short” will appear if users enter less than six characters into the field;
matches regular expression rule
  • Does not match regular expressions. The message will appear if users enter the symbols combination that matches the regular expressions;
  • Server-Side callback. There are three callbacks available:
    • Custom function. With this option, the Function Name field appears, where you can enter a function. Hit the “Show” button to get examples of function registering;
custom function
  • Is user login unique. The custom Error Message will appear if users try to enter the login that already exists on the website;
  • Is user email unique. The custom Error Message will appear if users try to enter the email that is already registered on the website.

Be aware that you can add two and more advanced rules to every form field by clicking the “+ Add Rule” button.

When you set all needed advanced rules and hit the “Update” button, you’ll see the rules and messages in the Validation block section.

advanced rule for the block

You can hover over it and click to edit or delete the rule.

edit or delete the advanced rule

Default

That’s the native validation that works by the browser.

default validation type

Advanced

Here, you can add the advanced rules described above and change the text of the error messages. The number of available messages is dependent on the field type and settings. All error messages are described in the Advanced Form Validation chapter. The custom messages set for the separate field will overtake the form validation settings.

advanced validation type for block

Checking Form Validation on the Front End

Proceed to the form or block Advanced Validation settings and set the custom error messages and advanced rules. Hit the “Update” button and place the form on the page. Open the page on the front end and fill in the form fields improperly to check the error messages.

advanced validation on the front end

That’s all. Now you know how to set the advanced validation and rules for the JetFormBuilder forms on the WordPress website.