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']
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.