[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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Related documentation: Front-end Content Submission and Editing Forms

This topic contains 2 replies, has 2 voices, and was last updated by  romanB-3 8 months 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)