List Fields
Table of Contents
Introduction
A list field contains and displays several text items in a scrollable list box. It is represented by the \setasign\SetaPDF2\FormFiller\Field\ListField class.
Setting and Getting Values
The \setasign\SetaPDF2\FormFiller\Field\ListField class offers, as any other field implementation, the getValue() and setValue() methods:
getValue()
Get the current value(s).
setValue()
Set the fields value / Selects the options.
The options of a list can have an export value and a visible value. Following method could be used to get the visible value:
getVisibleValue()
Get the current visible value(s).
To get the complete options list following method is available:
getOptions()
Get the options and the export values.
Field Type Specific Properties
Multi Select
A list field can have several active options if this flag is set. It can be handled by following methods:
isMultiSelect()
Checks if the field is a multi select field.
setMultiSelect()
Sets if the field is a multi select field.
Examples
// get the fields
$fields = $formFiller->getFields();
$listField = $fields->get('a simple list field');
$options = $listField->getOptions();
foreach ($options AS $index => $optionData) {
echo 'Option ' . $index . "\n";
echo 'Visible value: ' . $optionData['visibleValue'] . "\n";
echo 'Export value: ' . $optionData['exportValue'] . "\n";
}
$listField->setValue(2); // select option with index 2
$listField2 = $fields->get('multiselect');
$value = $listField2->getValue(); // is_array($value) === true
$listField2->setValue(array(0, 4)); // select options with index 0 and 4
$listField3 = $fields->get('an additional list field');
$listField3->setValue('export value 2');
