[Support request] code in footer.php

Home Forums Support [Support request] code in footer.php

Home Forums Support code in footer.php

  • This topic has 7 replies, 2 voices, and was last updated 2 years ago by David.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #922426
    Matthew

    I have been told to add below snippet to the footer.php, and doing so will enable CF7 plugin to not clear the form field values from all the fields in a form after its submitted.

    <script>
    document.addEventListener( ‘wpcf7mailsent’, function( event ) {
    jQuery(‘.wpcf7’).find(‘form’)[0].reset();
    }, false );
    </script>

    I added the above code as displayed into footer.php, but it’s not working. Am I doing something wrong? Should it be put in a certain area of the php file?

    I copied footer.php into my child theme folder first, then pasted the code into that.

    Also tried it with php open and close tags (instead of ‘script’)

    It seems weird to add this to the footer. Should it not be functions.php?

    thanks,

    #922448
    David
    Staff
    Customer Support

    Hi there,

    try adding the code to a Hook Element:

    https://docs.generatepress.com/article/hooks-element-overview/

    You can select the WP_Footer hook. And then set your display rules for the entire site or just the pages where the form is.

    #922472
    Matthew

    Hi David,

    thanks for the info about Elements. Learnt something new.

    Did exactly as you said but not working though. Can only assume the CF7 core file code is still overriding it

    wp-content\plugins\contact-form-7\includes\js\scripts.js

    `if ( ‘mail_sent’ == data.status ) {
    $form.each( function() {
    this.reset();
    } );`

    #922478
    David
    Staff
    Customer Support

    It could be. Where did you get the other code from? Does the provider of that provide any explanation?

    #922487
    Matthew

    I have just sent a support request about it to them,

    #922490
    David
    Staff
    Customer Support

    Let us know what they come back with

    #927660
    Matthew

    Ended up going with a direct edit to the plugin source as described here:

    https://wordpress.org/support/topic/how-to-not-clear-or-autofill-certain-fields-after-submission/

    not sure if this can be put in a ‘child theme’ for plugins. But it does work well. Radio and checkboxes clear the data so I use text fields and combo boxes only.

    thanks

    #927944
    David
    Staff
    Customer Support

    Glad to hear you found a solution.

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.