• kbotla

    (@kbotla)


    This has been a widely discussed topic but NO real solution. Like most people asking this question, I am trying to save the user from filling details on the form multiple times if he/she would like to download more than one file.

    Can you please tell me how to stop the form from clearing out?

    I have tried to do as described in a resolved post: https://www.ads-software.com/support/topic/keeping-fields-from-refreshing-on-submit?replies=8

    However, in CF7 4.3.1, in scripts.js, I do not see:
    if (1 == data.mailSent) {
    $(data.into).find(‘form’).resetForm().clearForm();
    ro.addClass(‘wpcf7-mail-sent-ok’);

    I only see:
    if (1 == data.mailSent) {
    $responseOutput.addClass(‘wpcf7-mail-sent-ok’);
    $form.addClass(‘sent’);

    if (data.onSentOk) {
    $.each(data.onSentOk, function(i, n) { eval(n) });
    }

    $(data.into).trigger(‘wpcf7:mailsent’);

    if (1 == data.mailSent) {
    $form.resetForm();
    }

    Now which part is causing the form to clear fields after submit? I would imagine its the resetForm() but I tried commenting out and it still clears the form

    https://www.ads-software.com/plugins/contact-form-7/

Viewing 2 replies - 1 through 2 (of 2 total)
  • I came across the same issue. The clearing/resetting for forms in CF7 v4.5 is done in the js file on the client side, triggered on success from the ajax submit, (file: contact-form-7/insludes/jquery.form.js` line 181)

    if (options.resetForm) {
            callbacks.push(function() { $form.resetForm(); });
        }
        if (options.clearForm) {
            callbacks.push(function() { $form.clearForm(options.includeHidden); });
        }

    where the options are passed in the ajax submit function (line 93),

    $.fn.ajaxSubmit = function(options) {

    the default options have the clearForm flag set to true. So to override this your need to call the ajaxSubmit with your own options values, and an example is provided in the comment on line 35,

    $(document).ready(function() {
            $('#myForm').on('submit', function(e) {
                e.preventDefault(); // <-- important
                $(this).ajaxSubmit({
                    clearForm: false
                });
            });
        });

    this will stop the clearing of the form.

    This is not not working for me… My script file is enqueued after the CF7 scripts, just to make sure everything exists when I call that. I can get a console.log(); to show on submit, but the ajaxSubmit() is not happening.

    Any help would be great, thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Stop CF7 from clearing fields after submit.’ is closed to new replies.