The Caldera globe logo with the words Caldera Forms below it

This dynamically named filter allows for adding custom validation for all fields of a specific type. The last part of the filter name is the field type, use “caldera_forms_validate_field_hidden” to affect all hidden fields or “caldera_forms_validate_field_email” to affect all email fields, etc.

Please take note that this filter exposes field and form config allowing you to target specific forms and/or fields by ID. In Caldera Forms 1.5.0, you can also use the “caldera_forms_validate_field_$field_id” filter to add validation to a field by ID.

This filter can be used to change the value of a field before it is saved. Also, it can be used to trigger validation errors. For example, to mark an option of select field as temporarily invalid, for instance if it represents and out of stock item. Returning a WP_Error on this filter will cause the form submission to stop and the WP_Error message to be displayed below the form.

Or you can trigger an error whenever a text field is less than 8 characters:

Where Does This Code Go?

When using WordPress hooks to customize Caldera Forms or other plugins you should not modify the plugin files, or you will lose your changes when you update the plugin. Instead you should create a small plugin to hold the custom code. It's easy, learn how here.

Technically you can add the custom code to your theme's functions.php, but then you will not be able to change your theme and keep these customizations.

Learn More

Leave a Reply

Your email address will not be published. Required fields are marked *