Title: Withdrawal button
Last modified: June 22, 2021

---

# Withdrawal button

 *  [sheilanana](https://wordpress.org/support/users/sheilanana/)
 * (@sheilanana)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/withdrawal-button/)
 * Hi,
 * Is it possible to have a “withdrawal button” besides/under/side of the “Send”
   button? So that it is possible to undo/withdraw the email after sending?
 * I hope it makes send. Thanks in advance.
 * Sheila
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fwithdrawal-button%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 15 replies - 1 through 15 (of 17 total)

1 [2](https://wordpress.org/support/topic/withdrawal-button/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/withdrawal-button/page/2/?output_format=md)

 *  [Erik](https://wordpress.org/support/users/codekraft/)
 * (@codekraft)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/withdrawal-button/#post-14583547)
 * Hi [@sheilanana](https://wordpress.org/support/users/sheilanana/)
 * i think it’s impossible because the mail was already delivered to another server
   where you have no privileges.
 *  Thread Starter [sheilanana](https://wordpress.org/support/users/sheilanana/)
 * (@sheilanana)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/withdrawal-button/#post-14583814)
 * Hi Erik,
 * Thanks for quick response.
 * Not even if it is within a few seconds?
 * – Sheila
 *  [Erik](https://wordpress.org/support/users/codekraft/)
 * (@codekraft)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/withdrawal-button/#post-14584066)
 * in this case yes!
 * it should be enough that you prevent the default when you click the submit button
   and then after a certain timeout make form.submit happen (if you don’t click 
   the button again).
 * some js is needed for this, if you need I can write it for you!
 *  [Erik](https://wordpress.org/support/users/codekraft/)
 * (@codekraft)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/withdrawal-button/#post-14585394)
 * hope this fits your needs, I tried to make it configurable and I commented it,
   if there is something that is not clear I will update it
 *     ```
       var delay = 2000; // set the preferred delay before send email
       var interval = null; // don't touch this
   
       jQuery(function ($) {
   
         // displays the button in active state
         function sendDisplayON(btn) {
           btn.val('Abort?');
           btn.addClass('submitting');
           $(btn).siblings('.ajax-loader').css('visibility','visible');
         }
   
         // displays the button in normal state
         function sendDisplayOFF(btn) {
           btn.val('Send');
           btn.removeClass('submitting');
           $(btn).siblings('.ajax-loader').css('visibility','hidden');
         }
   
         // on submit
         $('.wpcf7 input[type="submit"]').on('click', function (e) {
   
           e.preventDefault(); // prevent form submit
   
           var btn = $(this); // store this button into a variable
   
           if (btn.hasClass('submitting')) {
   
             clearInterval(interval); // reset the timeout
             sendDisplayOFF(btn);
   
           } else {
   
             sendDisplayON(btn);
   
             interval = setInterval(function () { // waits delay var value then will trigger this function
   
               clearInterval(interval); // reset the timeout
               sendDisplayOFF(btn);
   
               wpcf7.submit(btn.closest("form")[0]); // non ajax forms -> btn.closest("form")[0].submit;
   
             }, delay);
           }
   
         });
       });
       ```
   
 * [https://gist.github.com/erikyo/a93e2a22392a13659029da0181a496a7](https://gist.github.com/erikyo/a93e2a22392a13659029da0181a496a7)
 *  Thread Starter [sheilanana](https://wordpress.org/support/users/sheilanana/)
 * (@sheilanana)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/withdrawal-button/#post-14586378)
 * Hi Erik,
 * Thank you so much!
 * I tried placing the code in my functions.php, but it came with an error. Please
   see: “syntax error, unexpected ‘var’ (T_VAR), expecting end of file”.
 * Should I place it somewhere else?
 * Thank you so much!
 *  [Erik](https://wordpress.org/support/users/codekraft/)
 * (@codekraft)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/withdrawal-button/#post-14586539)
 * ciao [@sheilanana](https://wordpress.org/support/users/sheilanana/)
 * because this is javascript code and can’t work in the php context.
 * You can add this code at the end of cf7 form template (to be used into a single
   form but you need to remove empty lines) or into script.js of your parent (or
   child) theme or even better, some themes have a field where place the js (usually
   next to the custom css).
 * it is possible that you have a place to write javascript, in this case I will
   prepare an action to put in function.php. let me know!
 *  Thread Starter [sheilanana](https://wordpress.org/support/users/sheilanana/)
 * (@sheilanana)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/withdrawal-button/#post-14586854)
 * Hi Erik,
 * I have tried to place it under the single contactform under “additional settings”
   
   and I don’t see a script.js.
 * I also tried “Google Analytics Tracking Code”, seen in my themes (Enfold) documentation.
 * Is it maybe possible for you to access my site and tell me where to place it?
 * Thanks in advance!
    – Sheila 🙂
    -  This reply was modified 4 years, 11 months ago by [sheilanana](https://wordpress.org/support/users/sheilanana/).
 *  [Erik](https://wordpress.org/support/users/codekraft/)
 * (@codekraft)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/withdrawal-button/#post-14586924)
 * No, absolutely no, it’s against the rules! i can show you how to use that code,
   that is better!
 * In your case the easy/faster way is to add that code in the functions.php, but
   before you need to wrap it into:
 *     ```
       function my_scripts() { ?>
       	<script>
             var delay = 2000; // set the preferred delay before send email
             var interval = null; // don't touch this
   
             jQuery(function ($) {
   
               // displays the button in active state
               function sendDisplayON(btn) {
                 btn.val('Abort?');
                 btn.addClass('submitting');
                 $(btn).siblings('.ajax-loader').css('visibility','visible');
               }
   
               // displays the button in normal state
               function sendDisplayOFF(btn) {
                 btn.val('Send');
                 btn.removeClass('submitting');
                 $(btn).siblings('.ajax-loader').css('visibility','hidden');
               }
   
               // on submit
               $('.wpcf7 input[type="submit"]').on('click', function (e) {
   
                 e.preventDefault(); // prevent form submit
   
                 var btn = $(this); // store this button into a variable
   
                 if (btn.hasClass('submitting')) {
   
                   clearInterval(interval); // reset the timeout
                   sendDisplayOFF(btn);
   
                 } else {
   
                   sendDisplayON(btn);
   
                   interval = setInterval(function () { // waits delay var value then will trigger this function
   
                     clearInterval(interval); // reset the timeout
                     sendDisplayOFF(btn);
   
                     wpcf7.submit(btn.closest("form")[0]); // non ajax forms -> btn.closest("form")[0].submit;
   
                   }, delay);
                 }
   
               });
             });
       	</script>
       <?php }
       add_action('wp_enqueue_scripts', 'my_scripts', 99);
       ```
   
 * (untested let me know if has worked)
 *  Thread Starter [sheilanana](https://wordpress.org/support/users/sheilanana/)
 * (@sheilanana)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/withdrawal-button/#post-14586957)
 * Hi Erik,
 * I tried and it came up with this agiain: “syntax error, unexpected end of file”
 *  [Erik](https://wordpress.org/support/users/codekraft/)
 * (@codekraft)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/withdrawal-button/#post-14586994)
 * this happens usually because the quotes changes (sometimes while copy and paste)
   or if you have not copied all the code inside the gray box, try again and add
   it at the end of functions.php (remove “?>” at the end if there is)
 *  Thread Starter [sheilanana](https://wordpress.org/support/users/sheilanana/)
 * (@sheilanana)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/withdrawal-button/#post-14587032)
 * Super it worked!
 * Now what do I place in the forms to make it show?
 *  [Erik](https://wordpress.org/support/users/codekraft/)
 * (@codekraft)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/withdrawal-button/#post-14587184)
 * nothing, the scripts hooks directly to each submit button inside contact form
   7.
 * eventually you can hack the settings:
 * `var delay = 2000; // set the preferred delay before send email`
 * displays the button in active state
 *     ```
       function sendDisplayON(btn) {
         btn.val('Abort?'); // withdraw text
         btn.addClass('submitting'); // you can change the class
         $(btn).siblings('.ajax-loader').css('visibility','visible'); // style the loader?
       }
       ```
   
 * displays the button in normal state
 *     ```
       function sendDisplayOFF(btn) {
         btn.val('Send'); // original text, my bad i can store this value... this script need to be refined!
         btn.removeClass('submitting'); // you can change the class but need to be the same 
         $(btn).siblings('.ajax-loader').css('visibility','hidden');
       }
       ```
   
 *  Thread Starter [sheilanana](https://wordpress.org/support/users/sheilanana/)
 * (@sheilanana)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/withdrawal-button/#post-14587454)
 * Okay thank you Erik – but when I press “Send”, there is no “abort/withdrawal 
   button” appearing?
    Has I misunderstood something.
 *  [Erik](https://wordpress.org/support/users/codekraft/)
 * (@codekraft)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/withdrawal-button/#post-14587752)
 * yep sorry [@sheilanana](https://wordpress.org/support/users/sheilanana/) i said
   it wasn’t tested and it’s true!
 * you need to change the last line with
    `add_action('wp_footer', 'my_scripts',
   10);`
 * at the place of
    `add_action('wp_enqueue_scripts', 'my_scripts', 99);`
 * try this form if works as expected:
    [https://modul-r.codekraft.it/test-form/](https://modul-r.codekraft.it/test-form/)
    -  This reply was modified 4 years, 11 months ago by [Erik](https://wordpress.org/support/users/codekraft/).
 *  Thread Starter [sheilanana](https://wordpress.org/support/users/sheilanana/)
 * (@sheilanana)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/withdrawal-button/#post-14587839)
 * Hi Erik,
 * It works perfectly!!! Thank you so much!
 * Have a wonderful day!

Viewing 15 replies - 1 through 15 (of 17 total)

1 [2](https://wordpress.org/support/topic/withdrawal-button/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/withdrawal-button/page/2/?output_format=md)

The topic ‘Withdrawal button’ is closed to new replies.

 * ![](https://ps.w.org/contact-form-7/assets/icon.svg?rev=2339255)
 * [Contact Form 7](https://wordpress.org/plugins/contact-form-7/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/contact-form-7/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/contact-form-7/)
 * [Active Topics](https://wordpress.org/support/plugin/contact-form-7/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/contact-form-7/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/contact-form-7/reviews/)

 * 17 replies
 * 2 participants
 * Last reply from: [sheilanana](https://wordpress.org/support/users/sheilanana/)
 * Last activity: [4 years, 11 months ago](https://wordpress.org/support/topic/withdrawal-button/page/2/#post-14587905)
 * Status: not resolved