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
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
Hello Shane,
It is a single checkbox field !
Best regards,
Wilhem
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
Well, thank you Shane, it's fine but a proper way with a toolset function would have been appreciated !
Best,
Wilhem
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');
}
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
My issue is resolved now. Thank you!