[Resolved] AJAX bug on cred_save_data function for multiple

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.

Our next available supporter will answer your ticket in about 10.61 hours from now. Thank you for your understanding.

You are not logged in. You can view support threads, but not post.
If you are already logged in, please refresh your browser.

Related documentation: Front-end Content Submission and Editing Forms

This topic contains 2 replies, has 2 voices, and was last updated by  romanB-3 6 days, 6 hours ago. The support staff assigned to this topic is Shane.

Viewing 3 posts - 1 through 3 (of 3 total)
Author
Posts
#526312

Hello,

Beda helped me working out a solution to replace post's publication date when it's been edited in the cred form here : https://wp-types.com/forums/topic/update-post-published-date-from-a-custom-date-field/#post-507723

I then tried to also apply this function to 3 other forms, and modified it like this :

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

But now I noticed it's causing an AJAX bug as described here https://wp-types.com/forums/topic/ajax-error-when-submitting-form/, where Noman noticed the bug is solved when the function is limited to only one form. So I understand the bug comes from this part of the code :

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

Thank you.

#526379

Shane
Forum moderator

Supporter languages: English (English )

Supporter Timezone: America/Jamaica (GMT-05:00)

Hi Roman,

Thank you for contacting our support forum.

Could you try using an If statement like this.

if ($form_data['id']==1754 || $form_data['id']==2361 || $form_data['id']==2405 || $form_data['id']==2429)

Thanks,
Shane

#526691

Thank you very much ! Just perfect.

Viewing 3 posts - 1 through 3 (of 3 total)

You are not logged in. You can view support threads, but not post.
If you are already logged in, please refresh your browser.

Known issues and their solutions

We document known issues and their solutions in Toolset erratas. Save time by checking there first and seeing if what you are facing is a known issue. This list is kept short. We do our best to resolve all known issues with every release of Toolset plugins.

Support Policy

Toolset staff will help you use the Toolset plugins correctly, provide any information you need, help troubleshoot problems and advice on best-practices.

Please make sure to issue only one topic per each support ticket.

For more information, read our full Customer Support Policy.

Need custom programming work for your site? Check out our certified partners.