Support

Account

Home Forums General Issues Trigger Validation and after validation success halt the default publish action

Unread

Trigger Validation and after validation success halt the default publish action

  • Hello Team,
    In the WordPress admin panel while creating posts, pages etc. we have created fields with the help of ACF. Now when we click the publish (Update) button the form gets submitted and before that the front end JS validation gets called.
    I want to do lot of custom action after Validations and before form submission/publish.

    I found two ways to do it but both failed

    Case 1. using validation complete hook as follows
    acf.add_filter(‘validation_complete’, function( json, $form ){
    if( json.errors ) {
    // do nothing as it naturally halts the form submit and shows errors
    }
    else{
    // my code here for my purpose to achieve lot of stuff, after this I will manually trigger publish

    json = {valid: 0,errors:1};/* forcing to halt by altering json value */
    }
    return json;
    });

    After lot of attempts I figures out that altering the value of json to valid 0 and error 1 is the only way to halt the execution after validation complete. But that is not what i want as it shows validation error ribbon.
    ——case 1 ends———

    Case 2. I created a new button next to publish and on click of that I’m calling validation. Reference – https://support.advancedcustomfields.com/forums/topic/fire-validation-manually/#post-71784

    $(‘#MyCustomButton’).click(function(e){
    acf.validation.fetch( $(‘#post’) );
    });

    This solution works as well. But it works only till validation error exists. If there are no validation error then it submits the form/Publishes the post. Is there a way to stop it after validation success and before Publish?
    ——-case 2 ends———–

Viewing 1 post (of 1 total)

The topic ‘Trigger Validation and after validation success halt the default publish action’ is closed to new replies.