Skip Navigation

[Resolved] I need to fire a javascript function after a Toolset Form Saves.

This support ticket is created 5 years, 7 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 7 replies, has 2 voices.

Last updated by Beda 4 years, 9 months ago.

Assisted by: Beda.

Author
Posts
#1239379

Hi,

I have a toolset form which saves via ajax. Once the post is saved, the form remains in place (no page reload).
I need to call a javascript function once this happens. I am already calling it on page ready, but this event does not fire when I submit the form, as I checked "Submit this form without reloading the page (use AJAX)"

how can I do this?

#1239382

Every Forms API Hook listed here also works on AJAX Forms:
https://toolset.com/documentation/programmer-reference/cred-api/

So, if you want to hook in once the form is saving the post in the database, you can use cred_save_data():
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

This hook happens whenever the Form (whether AJAX or not) saves the data to the database.
You also have a hook just after that (https://toolset.com/documentation/programmer-reference/cred-api/#cred_submit_complete) and before that (https://toolset.com/documentation/programmer-reference/cred-api/#cred_before_save_data)

Hope this helps!

#1239407

Hi Beda, than you for answering.
I am looking for something purely javascript based that runs on the frontend.
something like after the cred form saved -> call a javascript function.

Or better yet:
Is there an event that fires when the ajax form reloads?
For example: how does the form know to display the success or failed message with the "Submit this form without reloading the page (use AJAX)" option turned on?

Can I do

.onThatEvent(function(){
something
});
#1240296

As you surely noticed, a success message only displays after the form submitted and as well reloaded the page, despite the AJAX submit.
The only "true" AJAX submit Toolset Forms features is "keep display the form".
Eventually, you mean that Success Message?
(Generally "Post Saved" in a DIV "alert alert-success", which is rendered by the ShortCode "form-messages" in the Toolset Form.
([cred_field field='form_messages' class='alert alert-warning'])

This is made by the JS cred_ajax_form Action.

You can try these events:
js_event_cred_ajax_form_response_completed triggered at jQuery(document)
I have written about this in past and it's still up to date:
https://toolset.com/forums/topic/js-function-stops-working-with-ajax-submission/#post-419260

It's the only (and undocumented) hook for AJAX events in Toolset Forms.
You can read the Developers explanation here https://toolset.com/forums/topic/js-function-stops-working-with-ajax-submission/#post-426646

I'm clarifying whether this would be a Feature Request or if we will add a proper JS API to Forms in any future release, I will update you here about the response of our Developers, so we can then decide if it requires a Feature Request.
For now, above is the only possibility - if you require assistance with complex custom code related to it, for now, I can recommend the Contractors here https://toolset.com/contractors/

#1240748

1. For any JS event which you need in a Form handled by AJAX, you would have to submit a Feature Request (https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/) suggesting to add such event.
==> Please be as precise as possible when describing where and when exactly the event should be usable in a form.

2. The current (self-explaining) events we have are:
- cred_form_ready
- toolset_repetitive_field_added
- js_event_cred_ajax_form_response_completed
- cred-post-delete-link-completed

None of them is documented and hence, I cannot fully support code or how-to issues related to them. We do currently overhaul the AJAX experience of Forms, and after that, our Developer agreed to eventually document some of the above, if still existent after the overhaul

I can hence not recommend using any of those, as they might change.
The current state of AJAX forms and events is, there are none (officially) to be used.

3. Concluding, if you need a solution immediately and need assistance with the custom code, you'd have to contact a Contractor https://toolset.com/contractors/.
If you can wait and would like to see more actions in the forms for you to use, you should submit a request for each action (or all bundled in one, but detailed) to the link shared above.

#1241055

Makes more sense to wait. Any way we can leave this ticket open until the new version gets released?

#1241386

Well, the new versions will as said not hold any new hooks, but after that, we might document what's left of the current ones.
New public Hooks API won't be added unless users like you request it here https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

I can, of course, keep this ticket open and notify you when Forms is out and that DOC eventually prepared and published, however, there is no warranty there will be (many) documented API hooks for this at all.

In that case, I would set this tentatively to "Escalated to Developers", however without a guarantee that something will be done to satisfyingly solve this issue.

It makes however sense to wait until then, to see what you will need additionally to that.

#1550561

This is a feature request that has not yet received any development.
Tentatively a fix version was postponed to 2 major releases ahead but this can change.

I suggest you submit the very voice for your request as well to https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/, I am adding it here also so other users can add their voices.

There is currently no safe AJAX API or reliable actions to hook in, hence there is also no documentation updated as of yet.