I have a form with two buttons (submit and save). The submit button sets the entry in pending status and the save button sets the entry in draft status.
The only problem I have is that most of my fields are required and when I select the save button, it requires the user to fill out all the required fields before selecting save or submit.
I am not sure how to bypass the required fields so that the entry/post could save as a draft. Is this possible?
Any resources and help would help.
Thanks!
@hello-tenika – were you ever able to figure this out? I am about to run up on the exact same issue myself. Thanks!
For anyone else that stumbled upon this, I followed some instructions that one of the help desk guys gave me
———–
For this kind of requirement, you could set the post_status on the acf_form() to ‘draft’ so that any changes made to the form will not be required to pass validation. You could then create some custom logic within the acf/validate_save_post to ignore all the errors if the post status is ‘draft’. The final step will be to hook into the acf/save_post to determine if all the fields have been filled and then change the post_status to publish.
Please take a look at the following resources that may help:
https://www.advancedcustomfields.com/resources/acf-save_post/
** https://www.advancedcustomfields.com/resources/acf-validate_save_post/ **
I hope this info helps.
—————
I followed the instructions in the item I have asterisks around. I created a “True/False” field that stated: “Are you ready to validate your application?” If that is FALSE, I clear all errors with acf_reset_validation_errors()
Hello Chris, I try to use acf_reset_validation_errors()
inside acf/validate_save_post
.
I can see the request to admin-ajax.php and it returns {"success":true,"data":{"valid":1,"errors":0}}
but the error messages still appear and the post isn’t saved.
I have set post_status
to draft
and I have this :
add_action('acf/validate_save_post', 'clear_all_errors', 10, 0);
function clear_all_errors() {
acf_reset_validation_errors();
}
Can you share some code about how you did it ?
EDIT : It was because now ACF use the required
on inputs
I’ve added formnovalidate
on my submit button and it solved my issue.