PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Show Validation Message in Template for Hidden Forms

  1. I have a form that is hidden on page load, but displayed on a click event using javascript.

    This is problematic when validation errors occur, as the form is hidden again after the failed submission.

    Is there a way I can easily check if there is an error, and display a message in my template?

    Posted 12 years ago on Tuesday October 23, 2012 | Permalink
  2. I found a decent solution for this, that also takes care of the confirmation message.

    In my functions file I check to see if the for is submitted. Within my logic, I used the wp_footer hook to print a little javascript to scroll down to the bottom of the page, and show the form.

    So here is the entirety of my solution, all in the functions file without touching the template:

    if ( $_POST[ 'is_submit_1' ] == true ) :
    
    add_action( 'wp_footer', function()
    { ?>
    <script>
    $('html, body').animate({scrollTop:$(document).height()}, 'slow');
    $( '.contact_form' ).toggle( 'slow' );
    </script>
    <?php }, 99999);
    
    endif;
    Posted 12 years ago on Tuesday October 23, 2012 | Permalink
  3. Thanks for posting!

    Posted 12 years ago on Thursday October 25, 2012 | Permalink
  4. That js actually needs a wrapper, but you get the idea. Too late to edit.

    Posted 12 years ago on Thursday October 25, 2012 | Permalink