Same problem as now closed but not resolved topic Pre-select checkbox options/choices on form load . But new facts.
In case a user request (thru my form) cannot be served, I re-display the form, filling it from the recorded entry :
… $current_form_field->choices[$choice_num - 1][‘isSelected’] = true; … var_dump ($form[‘fields’]); … return $form;
The var_dump shows that the choice has been taken in account:
[“choices”]=> array(2) {
[0]=> array(4) { [“text”]=> string(8) “Adhérer” [“value”]=> string(8) “Adhérer” [“isSelected”]=> bool(true) [“price”]=> string(0) “” }
[1]=> array(4) { [“text”]=> string(6) “Donner” [“value”]=> string(6) “Donner” [“isSelected”]=> bool(true) [“price”]=> string(0) “” } }
Yet it is not displaid and there is no “checked” parameter in the html code:
All other fields types - among them, radio fields - are correctly re-displaid.
Thanks for your answers and wish you a happy new year !
richardw8k
(Richard Wawrzyniak (Gravity Forms))
January 18, 2025, 8:00pm
2
Is the $_POST
populated when you are trying to set that property?
Hi Richard !
Many thanks for your answer.
Yes : $_POST is used to transmit the entry id, and other data that will be sent by the bank after a payment.
During the tests I could see in the html page that checked radio buttons <input>
included ‘checked=”checked” :
<input class="gfield-choice-input" name="input_3" type="radio" value="10" checked="checked" id="choice_1_3_0" onchange="gformToggleRadioOther( this )" data-conditional-logic="visible">
Instead, checked checkboxes had not :
<input class="gfield-choice-input" name="input_1.1" type="checkbox" value="Adhérer" id="choice_1_1_1">
I guess something is lacking in the code that displays checkboxes ? Or shoud I trigger a script that checks the selected checkboxes ?
richardw8k
(Richard Wawrzyniak (Gravity Forms))
January 20, 2025, 8:17am
4
Once the $_POST
is populated, the choice isSelected
property is not used, the plugin uses the contents of the $_POST
to determine which choices are selected. You’ll need to set the selected choice in the $_POST
e.g.
$_POST['input_1_1'] = 'Adhérer';
OK. Thank you Richard for this very clear answer.
I won’t be able to add this $_POST perameter because the request commes from the bank. So I will echo a script:
for each checkbox entry element:
if ($valeur_champ_entry <> "") { $current_form_field->choices[$num_sous_champ - 1]['isSelected'] = true; $toBeChecked[] = [("choice_1_" . $num_champ . "_" . $num_sous_champ) => 'true']; } else { $toBeChecked[] = [("choice_1_" . $num_champ . "_" . $num_sous_champ) => 'false']; }
before returning gform : check_checkboxes ($toBeChecked);
function check_checkboxes ($elementsIds) {
$checker = "<script type='text/javascript'>window.onload = function() {";
foreach ($elementsIds As $cbId) {
$elementId = array_keys($cbId)[0];
$elementValue = $cbId[$elementId];
$checker = $checker . 'document.getElementById("' . $elementId . '").checked = ' . $elementValue . ';';
}
$checker = $checker . "};</script>";
echo $checker;
return;
}
… and it does the job !
system
(system)
Closed
February 19, 2025, 11:34am
6
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.