Skip Navigation

[Resolved] Customize the post title using $_POST or $fields

This support ticket is created 3 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 1 reply, has 2 voices.

Last updated by Christian Cox 3 years, 11 months ago.

Assisted by: Christian Cox.

Author
Posts
#1984861

Dear Sir/Madam,

I have a CRED form, I want to customize the post title, there is a custom field in the form, don't know why I can only get the field value by using $_POST['wpcf-application-tour-number'] but not $fields['wpcf-application-tour-number']['value']

below is the code I do

function my_save_data_action($post_id, $form_data)
{
    if ($form_data['id']==211)
    {
        $current_user = wp_get_current_user();
       wp_update_post( array(
            'ID' => $post_id,
            'post_name' => $post_id,
            'post_title' => sprintf("%s - %s - %s", $_POST['wpcf-application-tour-number'], $post_id, $current_user->user_login)
    } 
}
add_action('cred_save_data', 'my_save_data_action',10,2);

here is the field I put in CRED form

[cred_field field='application-tour-number' force_type='field' class='form-control' output='bootstrap' urlparam='tour-id']
#1985741
Screen Shot 2021-03-14 at 11.55.42 AM.png
Screen Shot 2021-03-14 at 11.55.32 AM.png

don't know why I can only get the field value by using $_POST['wpcf-application-tour-number'] but not $fields['wpcf-application-tour-number']['value']
Hi, the short answer is you do not have access to the same information in all CRED APIs. The cred_save_data callback provides access to some information, but not the same information you might have access to in some other CRED APIs like cred_form_validate. You may consult the documentation to see which data parameters are available to each API function callback, for example:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

The $fields variable syntax you mentioned looks like it may have been copied from a cred_form_validate callback. That same information is not made available in a cred_save_data callback, so you must access similar information in the $_POST superglobal instead.