Skip Navigation

[Resolved] Load cred form with akax on frontend

This support ticket is created 6 years, 9 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 1 reply, has 2 voices.

Last updated by Beda 6 years, 9 months ago.

Assisted by: Beda.

Author
Posts
#616956

Hi,

I defined multiple custom posts type and a cred form for each custom type.

I have a front-end form with a dropdown to select a specific custom type.
When I select a custom type, I would like to load and display through ajax the related cred form.

I am not be able to load correctly the cred form, do you have any documentation for that ?

Thank you for your help

#616997

You can submit the CRED Form with AJAX if you set this in the CRED Form Edit screen "Other settings:" section.

This is how the form is submitted, not how it's loaded.
Forms in WordPress are made by HTML and how this is loaded, is determined not by CRED or the code that creates the form, but by the code that holds the form.

You can define in a form wether or not to submit it with AJAX, but you need to define in the code which holds the form, how to show it.

So if you have a button or similar somewhere, you can for example apply Custom JS to show a hidden part of your HTML on click where the CRED Form is inserted to.
Or, you can load a totally new page, but that requires a reload of the browser, hence you cannot do that with AJAX.

It's however not possible to achieve with Toolset Settings.
Imagine you would create a bare HTML form without even installing Toolset.

Still, you could not tell to this form to load by AJAX. You could only tell it to submit with AJAX.

You would still need to alter the way your whole HTML that holds this form is loaded, and that cannot be customized with Toolset in this way.

The closest you could get, would be to create a View, and load the Forms after submitting a AJAX Search.
That would load your form by AJAX after you click on a certain search term.

Let's say, you can create 4 different forms, and 4 different pages.
Insert each page a form.

Add a custom Field to pages, "CRED Form Title" (or whatever you like).
This should be a Single Line Field or similar.
The 4 single pages will all have a single value in this field, so to identify the CRED form they hold.
All other pages have no value saved for this field.

Then create a View, and query the Pages Post Type.
Add a Custom Filter for the Field that you add to Pages previously: "CRED Form Title"
I would choose selects filters.

Now, the View has a Custom Search for this field, so you can find the page with the related form by submitting this search.
You can do this with AJAX as you can set this in the Search settings for the View.

If you now limit the View to output one result only, and add a Conditional HTML to the loop that checks if the above field "CRED Form Title" is not empty, you should be able to insert this View to a Page, and when you view the page you will see one CRED Form.

When you change the search filter for "CRED Form Title" the results will be updated and show the only related form, and that will happen with AJAX.

Maybe this helps to achieve the goal.