I added the code in my theme's function.php file and validated fields names / form ID, but it doesn't work
I added the full url (hidden link...) in the 'whatever-value-you-like-or-url-to-image' part or the code. It is ok?
//Automatically adding a default image if none is uploaded
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']==20129)
{
if (!isset($_POST['photo']))//Change "my_custom_field" to your wpcf-field
{
// since $_POST['photo'] is not set (!isset())
update_post_meta($post_id, 'photo', 'hidden link');
}
}
}
Image slug: photo
Image link: hidden link
CRED form ID: 20129
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']==20129) {
if (!empty($_POST['wpcf-photo']) ) {
// since $_POST['photo'] is not set (!isset())
update_post_meta($post_id, 'wpcf-photo', '<em><u>hidden link</u></em>');
}
}
}
The thing is that Types custom field slug is prefix with 'wpvf-'{custom-field-slug}, so if you have custom field photo, internally it will be stored as wpcf-photo.
Could you please try above code and check if that help you to resolve your issue.
I've moved the custom code to "Custom code" section offered by Toolset:
=> hidden link
add_action('cred_save_data', 'func_set_default_image_cred_form',10,2);
function func_set_default_image_cred_form($post_id, $form_data) {
// if a specific form
if ($form_data['id']==20129) {
if (isset($_POST['wpcf-photo']) and empty($_POST['wpcf-photo']) ) {
update_post_meta($post_id, 'wpcf-photo', '<em><u>hidden link</u></em>');
}
}
}
I can see the default image is set:
=> hidden link