Skip Navigation

[Resolved] How do I validate fields in admin?

This thread is resolved. Here is a description of the problem and solution.

Problem:
How can I validate the input in Types Fields, in the WP Backend?

Solution:
The only options natively added by Toolset are the validation options you can see in Toolset > Post Fields > your_post_field_group > edit > your_field > edit > Validation

For a number field as example this can be:
- Required (can not be empty)
- Number (must be a number)

Relevant Documentation:
https://toolset.com/documentation/user-guides/using-custom-fields/

This support ticket is created 7 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 4 replies, has 2 voices.

Last updated by mikes-23 7 years, 10 months ago.

Assisted by: Beda.

Author
Posts
#424310

I have create a "product review" custom type. On that type I have added a numerical field called "rating". I want to ensure that when creating this post type this value is between 0-5. Is there any way I can validate for this using toolset? Also can I add a slider control?

Is this possible in toolset or do I have to write a separate plugin to validate the admin fields?

#424515

Validation can be done in two ways, using Toolset.

1. In the backend, the only options natively added by Toolset are the validation options you can see in Toolset > Post Fields > your_post_field_group > edit > your_field > edit > Validation

For a number field as example this can be:
- Required (can not be empty)
- Number (must be a number)

A minimum or maximum value can not be set here.
A possibility is to use Description an Place holders to inform the user about it.

2. With CRED, you can have better control, using the API.
https://toolset.com/documentation/user-guides/cred-api/#cfv

With that API filter you can validate any Field submitted via CRED in any way you like, using PHP to validate the content of the Fields.

#424532

Thanks for the reply.

Can cred do admin pages? I looked at the docs and I could only see instructions for front end forms.

#424558

No, CRED is intended only for the Front end.

Only a few features, like a notification when a certain Checbox is set, or Post Status changes to [...], would also trigger on the backend.

For backend solutions you should hook into save_post() and use a Custom PHP function.
https://codex.wordpress.org/Plugin_API/Action_Reference/save_post

#424639

OK, I will handle validation with my code.

This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.