Skip Navigation

[Resolved] AJAX error when submitting form

This thread is resolved. Here is a description of the problem and solution.

Problem:
AJAX error when submitting CRED form while AJAX is enabled. Then form is correctly registered but the site shows an error.

Solution:
The problem was in the custom functions added to the Child theme (functions.php file) which is generating the error when the form is submitted. So please make sure that your custom function is correct, in this case the problem was in this line:

 // if a specific form
    if ($form_data['id']==1754 || 2361 || 2405 || 2429) 

And changing it like this solved the problem:

// if a specific form
   if ($form_data['id']==1754)

Or like this:

if ($form_data['id']==1754 || $form_data['id']==2361 || $form_data['id']==2405 || $form_data['id']==2429)
This support ticket is created 6 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
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 13 replies, has 2 voices.

Last updated by romanB-3 6 years, 11 months ago.

Assisted by: Noman.

Author
Posts
#525635

Hello,
I need to activate AJAX on some of my forms but it generates an error. Then form is correctly registered but the site shows an error anyway.
Same problem I had here https://toolset.com/forums/topic/there-was-an-error-while-submitting-the-form/, now on various other CRED forms.
The error says "There was an error while submitting the form".
Thank you.

#525646

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Roman,

Thank you for getting in touch with us.

1. Please make sure all Toolset plugins are updated to latest versions as a primary check.
Also can you please share your Debug Information with us so we can see it? I have enabled debug info box for your next reply:
https://toolset.com/faq/provide-debug-information-faster-support/

2. Can you please also try to check it by deactivating all third-party plugins and switching back to the Default Theme (e.g. Twenty Sixteen theme) to see for any possible conflicts with any of the plugins or themes?

Thank you

#525992

Hello and thank you,
Just done this with no result ; bug still appears.
Thank you.

#526103

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello Roman,

To debug this issue further, I will need to take a look at your setup. So I need to request temporary access (WP-Admin and FTP Login info) to your staging site.

Your next answer will be private which means only you and I have access to it.

=== Please backup your database and website ===

✙ I would additionally need your permission to de-activate and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important.

✙ Please add the Links to the [Form] Edit Screen and [Page] Edit Screen where you have inserted this Form.

✙ Please provide me link or screenshot where the is displaying.

Looking forward to help you, Thank you

#526157

Hello and thank you,
This is a test site so you may activate and deactivate as you need.
Nevertheless it seems you forgot to activate the private reply.
Thank you.

#526173

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello Roman,

I have enabled private message box. Your next answer will be private which means only you and I have access to it.

Thank you

#526206

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello Roman,

I have thoroughly checked your site and found that the problem is in Avada Child theme which is generating the ajax error when the form is submitted.

I have activated Avada main theme, and now your form is submitted without any error. Can you please check now: hidden link

Thank you

#526218

It seems it is a problem within functions.php ; I erased it all and the bug disappears.
Could you please help me identifying which function is causing this ?

Also the whole site is in English now ; where did you set this ?

Thank you.

#526241

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello Roman,

I have activated debug mode in your site and tried to find out error, but there are no errors displayed on your site.

You can try to check your functions one by one, comment out or delete the functions one by one and check which function is causing the issue. Then modify and improve that function so that it would be working perfectly.

I have again changed the language to site’s default language.

Thank you

#526249

Hello and thank you,
I've done that and concluded it is the last function that causes the bug :

It's meant to replace post's publication date when it's been edited in the cred form.
The first part of the function should limit its action only to forms 1754 2361 2405 and 2429. But the form 2364 seems to be impacted too, since there is a bug on the page including it.

Please note I get this code from Beda here : https://toolset.com/forums/topic/update-post-published-date-from-a-custom-date-field/#post-507723

// Remplacer la date de publication du post lors de la saisie dans le cred form
add_action('cred_save_data', 'always_prefix_data_action',10,2);
function always_prefix_data_action($post_id, $form_data)
{
    // if a specific form
    if ($form_data['id']==1754 || 2361 || 2405 || 2429) 
    {
        //get post field value. This returns a TimeStamp if this is a Types Date Field
        $timestamp = get_post_meta($post_id, 'wpcf-date-de-la-depeche', true);
        $custom_date = gmdate("Y-m-d g:i:s", $timestamp);//convert timestamp to something like 2017-03-09 10:32:01 (Y/m/d g:i:s) for output and storage in the Database.
 
        // Update post post_date (publication date) with this date
        // Create $post_id object
        $my_post = array(
                'ID'           => $post_id,
                'post_date'    => $custom_date,
        );
 
        // Update the post into the database
        wp_update_post( $my_post );
    }
}

Thank you.

#526268

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Roman,

Can you please try to use only one Form ID in your function and see if it still shows an error when submitting the form:

 // if a specific form
    if ($form_data['id']==1754)

If it still shows an error, then we need to debug the given code. Please kindly open a new ticket and we will help you to resolve that issue as well. This will help other users with similar problems to find solutions when searching the forum, I am not allowed to handle multiple issues in the same ticket. You can assign the new ticket to Beda and give reference of this ticket.

Thank you for your co-operation

#526309

In deed, the issue is this ; by letting only one form, the bug is corrected.
I'll open a new ticket, thank you.

#526319

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Okay that's nice. When you get a chance, can you please kindly mark this current ticket as resolved.

Have a great weekend,
Thank you

#526322

Thank you.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.