Skip Navigation

[Resolved] Catch Cred form before submission

This support ticket is created 3 years, 11 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 1 reply, has 2 voices.

Last updated by Christian Cox 3 years, 11 months ago.

Assisted by: Christian Cox.

Author
Posts
#1899067

Hi, I use a Cred Form to update custom fields of a CPT.
Before the Form is submitted (and the CPT is updated) I would need to do some operation with the new values entered into the Cred fields.

How do I read these values if the form haven't been submitted yet?

Thanks

Best

#1900237

Hello, two Forms API hooks are triggered before the post is updated:
cred_before_save_data - https://toolset.com/documentation/programmer-reference/cred-api/#cred_before_save_data
cred_form_validate - https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate

Normally you would use cred_before_save_data if you do not want to block the Form submission process. You should use cred_form_validate if you may want to block Form submission and display errors in the Form based on custom code criteria.

For example, let's say you want to verify the User has submitted a unique value for some custom field. If the value is not unique, you want to block the Form submission process. You must use cred_form_validate in this case to perform a post query based on that custom field value. If the value already exists, you can show an error in the Form and the post submission will be blocked until the User submits a unique custom field value. On the other hand, let's say you want to copy a custom field value into a related post. The hook cred_before_save_data should be used to perform automatic actions that do not impact the post submission process.

Let me know if you have questions about implementing either of these APIs.