This support ticket is created 4 years, 6 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.
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.
It works and the values get saved, the only thing is that i have both options showing up and i need the first option only in the first field, while the second option show up on the second field
I think the least hacky way to do this is to add connected radio inputs wherever you want them in your form directly (i.e. in expert mode on the form write the actual input tags rather than inserting the input using a cred field shortcode) and then use the cred_save_data hook to get the field value from the global $_POST object and update the post meta yourself.
I followed your suggestions and it works. can you confirm if i did everything the right way, would appreciate that!
1- added following code with my form ID
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']==12345)
{
if (isset($_POST['wpcf-winner-1']))
{
// add it to saved post meta
add_post_meta($post_id, 'wpcf-winner-1', $_POST['wpcf-winner-1'], true);
}
}
}
I am having an issue with the "EDIT" form. It doesn't save the values of the custom Radio Buttons!
I have added the ID of the edit form to the function. but this isn't working unless i add the original input of cred form.
the create post form work as expected, this issue show up only when editing the post
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data){
$ids = array("12345","67890");
// if a specific form
if (in_array($form_data['id'], $ids) ){
if (isset($_POST['wpcf-winner-1']))
{
// add it to saved post meta
add_post_meta($post_id, 'wpcf-winner-1', $_POST['wpcf-winner-1'], true);
}
if (isset($_POST['wpcf-winner-2']))
{
// add it to saved post meta
add_post_meta($post_id, 'wpcf-winner-2', $_POST['wpcf-winner-2'], true);
}
}
}
The function add_post_meta will only add the custom field where it doesn't already exist, it won't overwrite an existing value where you are editing a post.
You would need to change the add_post_meta calls to the following format to work both to add or update a custom field: