Skip Navigation

[Resolved] How to call script after form is saved (AJAX)

This support ticket is created 4 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 3 replies, has 2 voices.

Last updated by ericE-4 4 years, 11 months ago.

Assisted by: Minesh.

Author
Posts
#1497693

In order work around some deficiencies in the post forms module, I've had to execute some code when the form loads. However when the form is saved, all the workarounds disappear. Therefore, I need a way to re-execute them when the post form is saved/submitted.

How can I execute a script after the form has been saved?

#1497979

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Toolset Forms offers the PHP hooks cred_save_data and cred_submit_complete that should be run after form is submitted. However these hooks are PHP hooks that will run for both AJAX and non-AJAX forms.
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_submit_complete

As you said, you want to run some script after the form is submitted using AJAX. There are no native JS hooks available with AJAX form submit but if you can show me what exactly the script you want to hook-in/reinitialize after you submit the form using AJAX I will check with our Devs to know if is there any workaround.

For that - can you please share the problem URL where you added the form and what script you want to reinitialize and access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1501077

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check now: hidden link

I've added the following code to your form's JS editor box:

 
  function initialize1() {

  	jQuery(window).scroll(function() {
        var scroll = jQuery(window).scrollTop();
        if (scroll >= 109) {
            jQuery("body").addClass('sticky');
        } else {
            jQuery("body").removeClass("sticky");
        }
    });
 
  /* Fancy checkboxes */
    jQuery(".wpt-form-checkbox-label").each(function(){
      jQuery(this).children().insertBefore(jQuery(this));
    });

  // make thumbnail grids work with sortable (by default it only works wehen arranged in a single verticval column)
    jQuery(".js-wpt-field-items.js-wpt-repetitive").sortable();
    jQuery(".js-wpt-field-items.js-wpt-repetitive").disableSelection();


    jQuery(".featured-image .js-toolset-media-field-trigger").click(function(){
      jQuery(".featured-image").parent().parent().addClass("image-pending-replace");
    });
 
  }

jQuery(document).ajaxComplete(function (event, xhr, settings) {
  
    if(settings.hasOwnProperty('extraData')){
        initialize1();
    }
  	
});

Can you please confirm it works as expected.

#1502321

Thanks, that code

jQuery(document).ajaxComplete(function (event, xhr, settings) {
    if(settings.hasOwnProperty('extraData')){
.
.
.

is exactly what I needed. Too bad this isn't documented anywhere!