Skip Navigation

[Resolved] Delayed Validation to permit saving incomplete Custom Post Type

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 7 replies, has 2 voices.

Last updated by Minesh 1 year, 4 months ago.

Assisted by: Minesh.

Author
Posts
#2747375

Hi,

I would like to do the following:
- allow users to create and edit a custom post type
- allow users to save the incomplete post and come back to it.
- the custom post type will be quite long so they may need multiple sessions to complete it

The problem is with the required fields. There will be required fields but having those required fields will prevent the user from saving a partially completed form without filling those fields.

What I would like to do:
- have required fields
- but they don't get validated when the user saves a partially completed version of the form (maybe it has 'draft' status?)
- and when the user is ready to submit the post, then the validation would check to make sure everything is completed. If the post passes validation then it gets submitted.

I haven't found something in the documentation that would support this.

Any guidance would be much appreciated.

Thanks!

Richard

#2747757

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

In that case - you will require to follow the multi-step form that is actually not a Toolset feature but workaround that should help you to resolve your issue.

Can you please try to follow the following related ticket and try to resolve your issue.
- https://toolset.com/forums/topic/how-to-create-a-multi-step-form-using-toolset/#post-2375259

#2747980

Hi Minesh,

Thanks for getting back to me and for offering this solution. I see how this could be an answer but I actually need something different.

The form I'm building will be long and complicated. The person filling it out may need to come back to it multiple times, filling different fields before they can submit it. So they can't complete one part at a time as suggested with the multi-step form because they will have missing content throughout the form.

So.. can I set required fields but then suppress the validation or at least ignore the validation, when the user SAVES A DRAFT? And only follow the validation when they SUBMIT THE FORM?

Thanks again,

Richard

#2748704

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

You can use the Toolset Form's hook "cred_form_validate" in order to validate the form when user submit the form.
- https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate

Now, it's on you, if you dont set the validation rules with the custom field group where you manage the custom fields and only validate when you submit the form using hook: "cred_form_validate"

Another possible solution could be you set the validation with custom field group where you manage the custom field and later you should try to use the form's hook "cred_filter_field_before_add_to_form" where you can disable the validation rule for such fields.
- https://toolset.com/documentation/programmer-reference/cred-api/#cred_filter_field_before_add_to_form

Please check the following related ticket that might help you - where we set the validation rule but you can also use this to remove the validation rule.
- https://toolset.com/forums/topic/requiring-fields-in-cred-using-js-not-working/#post-2687203

#2748753

Hi Minesh,

Thanks for this answer. After reading your notes and following your links, I found a couple of other support posts that discuss aspects of this problem:

[Resolved] Adding a save button to my forms
https://toolset.com/forums/topic/adding-a-save-button-to-my-forms/
- Highlights the validation problem

[Resolved] Possibility of “Save” and also “Send and Close” button in Content form
https://toolset.com/forums/topic/possibility-of-save-and-also-send-and-close-button-in-content-form/
- Explains how to use two different Submit buttons. One for saving for future editing. And one for submitting and preventing further access.

I have a question about the form hooks. Are they applied before the form is displayed? Or can they be applied when submitting the form? It seems to me that they won't work if they are applied BEFORE. Those form hooks only provide a solution if they can be applied AFTER the form is submitted.

Please confirm.

In other words, is it possible to:
- disable validation when user hits 'Save'
- leave validation enabled when user hits 'Send and Close'

Thanks again!

Richard

#2749170

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I have a question about the form hooks. Are they applied before the form is displayed? Or can they be applied when submitting the form? It seems to me that they won't work if they are applied BEFORE. Those form hooks only provide a solution if they can be applied AFTER the form is submitted.
====>
The Toolset form hook as the name suggested "cred_filter_field_before_add_to_form" - it will run before the field is added to the form.
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_filter_field_before_add_to_form

Description
This filter enters into action before each field is added to a Form on the front-end of the site, and gives users the ability to modify several field attributes. Attributes vary by custom field type, so the examples here are generalized.

So lets say you set XX field required from the custom field group that is set to display with post type "Book", later you created the form to add new book item so by default the XX field is required but you can use the above hook "cred_filter_field_before_add_to_form" to remove the required validation.

I think this is the thing you want.

If you share real life scenario with your requirement and problem URL where you want to add the form as well as what is the flow of your site to add/edit the multi-step form and at what point you want to validate the things and at what point you want to remove the validation then I will be able to guide you in the right direction.

#2749648

Hi Minesh,

Thanks for this answer.

We're still building it. Will see if we can figure it out on our own based on your guidance. And will get back to you if we still need help.

Thanks,

Richard

#2749858

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Ok fine - Feel free to get in touch with me if you require further assistance.