I have a generic field in a CRED form and I added a save_data hook to my functions file to update a types custom field in the database with the value selected by the user but nothing is happening.
and this is the code I added to my functions file:-
add_action('cred_save_data', 'test_one_create_save_data_action',10,2);
function test_one_create_save_data_action($post_id, $form_data)
{
// This is the CRED form ID
if ($form_data['id']==131)
{
// 'time_of_day' is the field name in the CRED generic field setup
if (isset($_POST['time_of_day']))
{
// 'wpcf-time-of-day' is the meta key that the value of 'time_of_day' will be added to
add_post_meta($post_id, 'wpcf-time-of-day', $_POST['time_of_day'], true);
}
}
}
When I first tried it, I hadn't actually created a Types post field wpcf-time-of-day so I created it before trying again but the value selected using the generic field still isn't added to the database.
I'm not sure what I'm doing wrong. Can you help please?
Also, just to help me understand the generic field better, what role/purpose do the values I assign to Values have please?
Hello. Thank you for contacting the Toolset support.
This is strange - your code looks OK to me. To investigate this issue further I need problem URL where you added CRED form.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).
I have set the next reply to private which means only you and I have access to it.
Really sorry but this was down to me; I found some inconsistencies in my functions file that were causing issues, now I've removed them the code works. It's a test site so no harm done but a valuable lesson learned!