I have a checkbox in a single page:
echo $form->checkbox('policy', 1, '0');
echo t("I have read and agree to the") . ' <a href="' . \URL::to('/', 'terms') . '" target="_blank">' . t('Terms and Conditions') . '</a>';
I set its value with JS:
$('#policy').on('change', function() {
$(this).val(this.checked ? 1 : 0);
$(this).attr('checked', this.checked ? true : false);
}).trigger('change');
but the controller doesn't read its value.
I tried both of these:
$data = $this->post();
$policy = $data['policy'];
$policy = isset($data['policy']) ? 1 : 0;
The first one reads nothing, the second one always reads 0.
I know the save() function reads checkbox values but I don't save anything, my single page controller simply needs to check the form inputs and then route to another page.
How can I handle the checkbox in a single page controller without saving?
Aucun commentaire:
Enregistrer un commentaire