Skip Navigation

[Resolved] How to call the value of form's field.

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

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 4 replies, has 2 voices.

Last updated by Eko Wid 2 years, 9 months ago.

Assisted by: Shane.

Author
Posts
#2444193

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

Thank you

#2444221

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

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.

Thanks,
Shane

#2444827

Hi Shane,

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 );

}
}
}

Any suggestion?

#2444941

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

Set the form to display the form after submitting, not to display the success message.

If this doesn't work you can also use the error_log() function to write your variables to the php error log file.

Thanks,
Shane

#2445711

My issue is resolved now. Thank you!