Check Box Fields

Introduction

A check box field represents a kind of boolean field, that toggle between two states, on and off. It is represented by the class SetaPDF_FormFiller_Field_Button. Instances of this class are also used by the SetaPDF_FormFiller_Field_ButtonGroup for handling radio button groups.

Getting and Setting the State

A check box's state can be accessed in different ways. At the end it depends on your data and coding style. A setValue() method exists, that will set the state whether by a boolean value or whether the given value is the same export value of the field instance:

getValue()

Gets whether the button is checked or not.

setValue()

Check or un-check the button.

The class also offers intuitive methods to set or get the state of a check box. Internally they are used by the setValue() method as well. 

check()

Checks the button.

isChecked()

Gets whether the button is checked or not.

pull()

Alias for uncheck().

push()

Alias for check().

uncheck()

Uncheck the button.

Examples

PHP
// get the fields
$fields = $formFiller->getFields();
 
$btn = $fields->get('checkbox 1');
$btn->check();
 
$fields['checkbox 2']->uncheck();
 
$fields['checkbox 3']->setValue(true); // same as -> check()
$fields['checkbox 4']->setValue(false); // same as -> uncheck()
 
$fields['checkbox 5']->push(); // same as -> check()
$fields['checkbox 6']->pull(); // same as -> uncheck()
 
$btn6 = $fields->get('checkbox 6');
$btn6->setValue(!$btn6->isChecked()); // toggle
 
$exportValue = $btn6->getExportValue();
echo 'The export value of "checkbox 6" is "' . $exportValue . '"';