Tell us what you are trying to do? get the selected values of a checkbox field and passit into a urlparm
Is there any documentation that you are following? https://toolset.com/documentation/customizing-sites-using-php/functions/
Is there a similar example that we can see?
could find one
What is the link to your site?
lien caché
I'm using the code:
add_filter('cred_success_redirect', 'custom_redirect_func', 99, 3);
function custom_redirect_func($url, $post_id, $form_data)
{
if ($form_data['id']==86) // this is CRED form ID
{
$budget = get_post_meta($post_id, 'wpcf-my-budget-is', true);
$agegrp = get_post_meta($post_id, 'wpcf-age-group', true);
$teran = get_post_meta($post_id, 'wpcf-the-terrain-iride', true);
$radtyp = get_post_meta($post_id, 'wpcf-roadtyp-want-toride', true);
$freqncy = get_post_meta($post_id, 'wpcf-i-plan-to-ride', true);
$rdrgoal = get_post_meta($post_id, 'wpcf-usr-riding-goal', true);
$rdrhght = get_post_meta($post_id, 'wpcf-height', true);
$rdrwgt = get_post_meta($post_id, 'wpcf-weight', true);
$rdrtchskl = get_post_meta($post_id, 'wpcf-my-tech-rdng-skill', true);
$rdrftlvl = get_post_meta($post_id, 'wpcf-my-fitness-level-is', true);
$rdrsx = get_post_meta($post_id, 'wpcf-sex', true);
$rdrxprns = get_post_meta($post_id, 'wpcf-years-of-riding', true);
$url .= "?pr=" . $budget . "&ag=" . $agegrp . "&tn=" . $teran . "&rt=" . $radtyp . "&fr=" . $freqncy . "&gl=" . $rdrgoal . "&hg=" . $rdrhght . "&wt=" . $rdrwgt . "&sk=" . $rdrtchskl . "&fl=" . $rdrftlvl . "&gn=" . $rdrsx . "&ex=" . $rdrxprns;
// here add more URL parameters
}
return $url;
}
and i get the link:
lien caché
how can i change the results to display the actual values instead of the word "Array"
please advise,
thanks,
David
Dear David,
The custom checkboxes field of Types plugin stores value as a serialized array, I suggest you use Types function types_render_field() to render to field value, for example, modify this line from:
$radtyp = get_post_meta($post_id, 'wpcf-roadtyp-want-toride', true);
To:
$radtyp = types_render_field( "my-roadtyp-want-toride", array( "separator" => ", " ) )
See our document:
https://toolset.com/documentation/customizing-sites-using-php/functions/#checkboxes
click link "Repeater attributes, User attributes, Term attributes, Usage examples"
Hi Luo,
thanks for your response.
i tried this and change my code to:
add_filter('cred_success_redirect', 'custom_redirect_func', 99, 3);
function custom_redirect_func($url, $post_id, $form_data)
{
if ($form_data['id']==86) // this is CRED form ID
{
$budget = get_post_meta($post_id, 'wpcf-my-budget-is', true);
$agegrp = get_post_meta($post_id, 'wpcf-age-group', true);
$terans = get_post_meta($post_id, 'wpcf-the-terrain-iride', true);
$radtyp = types_render_field( "my-roadtyp-want-toride", array( "separator" => ", " ) ); //new line from toolset support
$freqncy = get_post_meta($post_id, 'wpcf-i-plan-to-ride', true);
$rdrgoal = get_post_meta($post_id, 'wpcf-usr-riding-goal', true);
$rdrhght = get_post_meta($post_id, 'wpcf-height', true);
$rdrwgt = get_post_meta($post_id, 'wpcf-weight', true);
$rdrtchskl = get_post_meta($post_id, 'wpcf-my-tech-rdng-skill', true);
$rdrftlvl = get_post_meta($post_id, 'wpcf-my-fitness-level-is', true);
$rdrsx = get_post_meta($post_id, 'wpcf-sex', true);
$rdrxprns = get_post_meta($post_id, 'wpcf-years-of-riding', true);
$url .= "?pr=" . $budget . "&ag=" . $agegrp . "&tn=" . $teransstrng . "&rt=" . $radtyp . "&fr=" . $freqncy . "&gl=" . $rdrgoal . "&hg=" . $rdrhght . "&wt=" . $rdrwgt . "&sk=" . $rdrtchskl . "&fl=" . $rdrftlvl . "&gn=" . $rdrsx . "&ex=" . $rdrxprns;
// here add more URL parameters
}
return $url;
}
but i get the urlparm "&rt" empty:
lien caché
any thoughts?
David
That is only an example, you will need to change the field slug according to your website settings, for example the custom field "roadtyp-want-toride", in your PHP codes, you can modify it as:
$radtyp = types_render_field( "roadtyp-want-toride", array( "separator" => ", " ) )
Hi Luo,
Oh, I overlooked the "my-" in the string...
that didn't work
I also added the prefix "wpcf-" to the field, didn't work either
$radtyp = types_render_field( "wpcf-roadtyp-want-toride", array( "separator" => ", " ) )
I wonder if this issue is because the code is working on a cred form and not a post i.e. the post id is not available so how does the "types_render_field" know which post to pull the custom filed from.
David
It is abnormal, it should be able to work on the post too.
Since it is a custom PHP codes problem, could you duplicate same problem in a test site, and fill below private detail box with login details and FTP access, also point out the problem page URL, and where I can edit you PHP codes, I need a live website to test and debug, thanks
Thanks for the detail, in your case you need to specific the post ID in the Types function types_render_field(), for example:
$radtyp = types_render_field( "roadtyp-want-toride", array( "post_id"=>$post_id, "separator" => "," ) );
ok, got it.
I know i have done in the past but don't remember how can i get the post_id when i submit the cred form.
David