Skip Navigation

[Gelöst] get a list of selected checkboxes and pass the values in urlparm

This support ticket is created vor 6 Jahre. 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.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

Dieses Thema enthält 8 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von davidZ-4 vor 5 Jahre, 12 Monate.

Assistiert von: Luo Yang.

Author
Artikel
#890174

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?
versteckter Link

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:

versteckter Link

how can i change the results to display the actual values instead of the word "Array"

please advise,
thanks,

David

#891251

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"

#891264

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:

versteckter Link

any thoughts?

David

#891267

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" => ", " ) )
#892595

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

#894952

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

#895059

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" => "," ) );
#895074

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

#895077

so tired...

I got it.

Thanks Luo

Dieses Ticket ist jetzt geschlossen. Wenn Sie ein Toolset Kunde sind und Hilfe benötigen, eröffnen Sie bitte ein neues Support-Ticket.