Skip Navigation

[Resolved] Populate Types checkbox field by a $_GET or $_POST value

This support ticket is created 2 years, 3 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 7 replies, has 2 voices.

Last updated by Wilhem 2 years, 3 months ago.

Assisted by: Shane.

Author
Posts
#2458981

Hello team,

Populate Types checkbox field by a $_GET or $_POST value :

I'm trying to populate a checkbox if I create a new post with a url like that :

.../post-new.php?post_type=cpt&express=true

Unfortunalty, I can't find a way to do this ? There is no default value for a checkbox and I can't find a wpt_field_options equivalent to wpt_field_checkbox

Please, can you help me ?
Best regards,
Wilhem

#2459185

Shane
Supporter

Languages: English (English )

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

Hi Wilhem,

Thank you for getting in touch.

Can you confirm if this is a single checkbox field or is a checkboxes group field.

Thanks,
Shane

#2459197

Hello Shane,

It is a single checkbox field !

Best regards,
Wilhem

#2459219

Shane
Supporter

Languages: English (English )

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

Hi Wilhem,

In this case you will need to employ the use of custom code to select the field.

Something like this will be needed.
https://stackoverflow.com/questions/66550268/check-checkboxes-based-on-url-parameters

Without the use of custom coding this is something that isn't possible.
Thanks,
Shane

#2459227

Well, thank you Shane, it's fine but a proper way with a toolset function would have been appreciated !
Best,
Wilhem

#2459231

To help :

You have to trigger to not loose toolset conditionals

var getUrlParameter = function getUrlParameter(sParam) {
var sPageURL = window.location.search.substring(1),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;

for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');

if (sParameterName[0] === sParam) {
return typeof sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
}
}
return false;
};

var express = getUrlParameter('express');
if ( express == '1' ) {
//$("input[data-wpt-id='wpcf-a-express']").prop("checked",true);
$("input[data-wpt-id='wpcf-a-express']").trigger('click');
}

#2459363

Shane
Supporter

Languages: English (English )

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

Hi Wilhem,

Thanks for sharing your solution.

What you can do is to go ahead and mark this ticket as resolved so that I can add your solution to the resolved thread summary for this ticket.

This way other users will be able easily able to find the solution should they have a similar issue.

Thanks,
Shane

#2459791

My issue is resolved now. Thank you!