Hi,
I have created custom code toolset as follows :
add_action('cred_save_data', 'set_image_as_featured',10,2);
function set_image_as_featured($post_id, $form_data)
{
// if a specific form
if ($form_data['id']==1506)
{
if (isset($_POST['wpcf-gallery']))
{
$image = $_POST['wpcf-gallery'][0];
// Save the first image as featured image
set_post_thumbnail($post_id,attachment_url_to_postid($image));
}
$people_gen_field = $_POST['person'];
// if a people post is selected
if(!empty($people_gen_field)) {
// Connect it in a relationship with the created post
toolset_connect_posts( 'journal-people', $post_id, $people_gen_field );
}
$location_gen_field = $_POST['location'];
// if a people post is selected
if(!empty($location_gen_field)) {
// Connect it in a relationship with the created post
toolset_connect_posts( 'journal-location', $post_id, $location_gen_field );
}
}
}
Is there any way to show the value of the variable (similar with console.log on JavaScript)? for example to echo/ var_dump the variable of $people_gen_field
Assuming here that you're not redirecting your form to a different page then you can use var_dump($variable) and then when you submit the form it should dump the value to the page.
Alternatively you can use the die() function to terminate the processes after the function and dumping out any value you've passed into the variable, example die(var_dump($variable))
Also this only works when the form is Not being submitted using AJAX.
Thank you for your respond. I tried already and it didn't work on my case. It's only show "successful message"
"Also this only works when the form is Not being submitted using AJAX".
Yes, I am not using AJAX and not redirecting the page.
add_action('cred_save_data', 'set_image_as_featured',10,2);
function set_image_as_featured($post_id, $form_data)
{
// if a specific form
if ($form_data['id']==1506)
{
if (isset($_POST['wpcf-gallery']))
{
$image = $_POST['wpcf-gallery'][0];
// Save the first image as featured image
set_post_thumbnail($post_id,attachment_url_to_postid($image));
}
$people_gen_field = $_POST['person'];
die(var_dump($people_gen_field))
// if a people post is selected
if(!empty($people_gen_field)) {
// Connect it in a relationship with the created post
toolset_connect_posts( 'journal-people', $post_id, $people_gen_field );
}
$location_gen_field = $_POST['location'];
// if a people post is selected
if(!empty($location_gen_field)) {
// Connect it in a relationship with the created post
toolset_connect_posts( 'journal-location', $post_id, $location_gen_field );