How to show a notice above the form when using filter mode

Created by Phil Kurth, Modified on Wed, 06 Mar 2024 at 01:18 PM by Phil Kurth

https://github.com/advancedforms/advanced-forms/blob/8787653b848bbd327e3192355c1a1a32122dd225/assets/js/forms.js#L370https://hookturn.io/docs/advanced-forms-for-acf/1.9/customizing-how-the-form-renders/When using a form to edit post/user profile information, it can make sense to use filter mode as a means of keeping the form in place after submission, much like a typical profile edit form. 


Advanced Forms Pro doesn't currently display any form of confirmation message but you may implement your own custom confirmation message using the following snippet as a starting point: 


<?php

add_filter( 'af/form/before_title', function ( $form, $args ) {

  // Restrict this handler to a specific form.
  if ( $form['key'] !== 'form_62d0d61d41e2b' ) {
    return;
  }

  // If we are currently processing a submission, append our message.
  if ( af_has_submission() ) {
    ?>
    <div>
      Custom update message goes here.
    </div>
    <?php
  }
}, 10, 2 );

There are a number of location based hooks which could be used See https://hookturn.io/docs/advanced-forms-for-acf/1.9/customizing-how-the-form-renders/


AJAX based form handling


The above approach only works if not using AJAX on the form. When using AJAX, the form UI isn't rebuilt so there is no opportunity to append the message. If you need to use AJAX in this situation, consider using some custom JavaScript attached to the af/form/ajax/submission JavaScript hook which can be seen here: 


https://github.com/advancedforms/advanced-forms/blob/8787653b848bbd327e3192355c1a1a32122dd225/assets/js/forms.js#L370


You may choose to use a combination of the hooked notice above and the JavaScript hook to hide show the notice when needed. 

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article