Text Fields Handling Single or Multiline Text Fields

Introduction

A text field in a PDF document is comparable with an input or textarea field you may know from HTML. Anyhow both types are represented by a single implementation in the PDF format. The SetaPDF-FormFiller represents such field type with an instance of the SetaPDF_FormFiller_Field_Text instance.

Getting and Setting Values

As you may expect a text field will hold a string value as its value. It may be accessed with the self-explanatory methods: 

getValue()

Get the field value.

setValue()

Set the field value.

Field Type Specific Properties

Multiline

To check or set a field for the multiline flag following methods are available: 

isMultiline()

Check if the multiline flag is set.

setMultiline()

Set the multiline flag.

Maximal Length

A text field could be restricted its value length. You may access this property by the getMaxLength() and setMaxLength() methods:

getMaxLength()

Get the max length property if available.

setMaxLength()

Set the max length property.

Comb

If a maximal length is defined an additional flag could be set that automatically divide the field into as many equally spaced positions (combs) as the maximal length value. The field value is laid out into those combs. 

isCombField()

Check if the comb field flag is set.

setCombField()

Set the comb field flag.

Password Field

The PDF format also defines password fields. You can check for them or define a field to be such one with the following methods: 

isPasswordField()

Check if the password field flag is set.

setPasswordField()

Set the password field flag.

Do Not Spell Check

A flag, that defines that the text entered in a field shall not be spell-checked can be handled with following methods: 

isDoNotSpellCheckSet()

Check if the "do not spell check" flag is set.

setDoNotSpellCheck()

Set the "do not spell check" flag.

Do Not Scroll

If the value does not fit into the rectangle of a text field the viewer application will display scrollbars if you focus the field. Additionally it will display a plus-sign which should give a hint about unseen content in a field. You can define this behavior with the following methods: 

isDoNotScrollSet()

Check if the "do not scroll" flag is set.

setDoNotScroll()

Set the "do not scroll" flag.

Examples

PHP
// get the fields
$fields = $formFiller->getFields();
 
// access a field through the ArrayAccess implementation
$fields['my text field']->setValue('A simple test with some chars');
 
// let's play with a multiline field
$multilineField = $fields->get('a multiline text field');
if (!$multilineField->isMultiline()) { // just as an example...
    $multilineField->setMultiline();
}
$multilineField->setValue("Line 1\nLine 2\nLine 3\n...");
 
// get a value
$value = $fields['age']->getValue();
if ($value < 0) {
    echo 'You should at least be born.'; 
}