8.4.2 How to handle checkbox in single page controller?

Permalink
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?

linuxoid
 
linuxoid replied on at Permalink Reply
linuxoid
Doh! I forgot I was using ajax where I forgot to add the checkbox value to the data array...

All is working fine actually