Hi,
I would like to add a default value to a custom field whenever someone submits a specific form. However I do not want that field to be visible on the form. I've found the documentation on cred_save_data and this looks like what I want. I'm just not sure how to edit this code for my use.
The field I want to give a value to is – "wpcf-email-newsletter"
The field is a checkbox which I would like to default as checked when the form is saved
The form id is "527"
The slug for the post type is – "organisation"
Here's the sample code given.
add_action(‘cred_save_data’, ’my_save_data_action’,10,2);
function my_save_data_action($post_id, $form_data)
{
// if a specific form
if ($form_data[‘id’]==12)
{
if (isset($_POST[‘my_custom_field’]))
{
// add it to saved post meta
add_post_meta($post_id, '__my_custom_field', $_POST['my_custom_field'], true);
}
}
}
Would someone be able to show me what needs changing to get it to work?
Thanks,
Charlie