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.
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.
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?
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.
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.
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 ?
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.
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.
// 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 );
}
}
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.