Skip Navigation

[Resolved] CRED Save Data Hook Not Updating Custom Field

This support ticket is created 7 years, 3 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by julieP 7 years, 3 months ago.

Assisted by: Minesh.

Author
Posts
#552876

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.

This is the code for my generic field:-

[cred_generic_field field='time_of_day' type='select' class='' urlparam='']
{
"required":0,
"validate_format":0,
"default":[],
"options":[
{"value":"1","label":"10.00"},
{"value":"2","label":"11.00"},
{"value":"3","label":"12.00"},
{"value":"4","label":"13.00"}
]
}
[/cred_generic_field]

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?

Many thanks

#553029

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

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.

#553381

Hi Minesh

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!

Thanks for checking my code 🙂