Version 5.9.40

Formfield

since version 5.9.40

Creates a form field that can be filled in with a PDF viewer: a text field, a check box, a radio button or a choice field (combo box or list box). The field can stand in a paragraph (like an image in the text), in PlaceObject or directly in Td. In a table cell, a text field or choice field without width fills the width of the cell, and without height its height.

The field name is required. Dots in the name build a hierarchy (order.item.4711.quantity), as the tools for reading the form data return it. A name can be used only once, unless the field has shared="yes". Radio buttons with the same name form a group, of which only one can be selected; each button needs its own value.

The entries of a choice field are given with Option, also from the data with ForAll or Loop.

Without CSS or attributes, a field has neither a border nor a background. Border and background of text fields and choice fields are visible on the screen only, they are not printed, so a printed form looks like a paper form with the values filled in (except in PDF/A and PDF/UA, which do not allow this). The publisher draws the initial appearance of the field with the font of the surrounding text. While editing, the PDF viewer draws the field itself, with Helvetica or, if fontfamily is given, with the regular font of that family, which is then embedded completely.

In PDF/UA, every field becomes a structure element Form in the paragraph or table cell around it. PDF/X does not allow form fields: the publisher outputs only their initial appearance, with a warning.

Child elements

Copy-of, ForAll, Loop, Option, Switch

Parent elements

A, B, Color, Fontface, I, Li, NoBreak, Paragraph, PlaceObject, Span, Td, U, URL

Attributes

background-color (text, optional, CSS property: background-color)
Background color of the field.
border-color (text, optional)
Color of the border on all four sides. Default: the text color.
border-style (text, optional)
Style of the border on all four sides: solid, dashed, dotted or none. With border-width alone, the border is solid.
border-width (length, optional)
Width of the border on all four sides. CSS can set the sides individually, for example border-bottom: 0.5pt solid for a field with a line below.
checked (yes or no, optional)
For a check box or a radio button: is it checked initially? In a group of radio buttons only one can be checked. Default: no.
class (text, optional)
CSS class for this field.
color (text, optional, CSS property: color)
Color of the text, of the cross in a check box and of the dot in a radio button.
editable (yes or no, optional)
For a combo box: can text be entered that is not one of the options? Default: no.
fontfamily (text, optional)
Font family of the field. Without this attribute, the field uses the font family of the surrounding text for its initial appearance and Helvetica for editing. With this attribute, the regular font of the family is also used for editing and is embedded completely, so that the viewer can display all characters it contains. Required for text fields and choice fields in PDF/A.
height (number or length, optional)
Height of the field (in grid cells or as a length). Default for a text field: 1.5 times the font size, for a multi line text field three lines, for a list box up to five entries, for a check box and a radio button the font size.
id (text, optional)
CSS id for this field.
list (yes or no, optional)
For a choice field: show the entries as a list box instead of a combo box (drop down list). Default: no.
maxlength (number, optional)
For a text field: the maximum number of characters that can be entered.
minwidth (length, optional)
For a text field or choice field that fills a table cell: the width the column needs at least. Default: twice the font size.
multiline (yes or no, optional)
For a text field: can the text have several lines? Default: no.
name (text)
The name of the field. Dots separate the levels of the hierarchy. The name is used when reading out the form data, for example {concat('order.item.', @id, '.quantity')}.
readonly (yes or no, optional)
Can the field be changed in the viewer? Default: no (it can be changed).
required (yes or no, optional)
Must the field be filled in? Viewers mark such fields, but do not all check them. Default: no.
shared (yes or no, optional)
The field appears several times with the same name, for example on every page or in a repeated table head. All occurrences show the same value. Without this attribute, a second field with the same name is an error. Default: no. The macOS Preview app does not handle shared fields correctly.
style (text, optional)
CSS declarations for this element, as in the HTML attribute style, for example border: 1pt solid red. They take precedence over the CSS rules, but not over the attributes, unless they are marked !important. An empty value is ignored.
tooltip (text, optional)
Short description of the field. Viewers show it when the mouse is over the field, screen readers read it out. Required in PDF/UA.
type (optional)
The kind of field.
  • text: A text field (default).
  • checkbox: A check box.
  • radio: A radio button. Buttons with the same name form a group.
  • choice: A choice field with the entries given by Option: a combo box, or with list="yes" a list box.
value (text, optional)
For a text field: the initial text. For a check box or a radio button: the value that the form data contain when it is checked (check box default: Yes; unchecked, the value is always Off). Required for radio buttons. For a choice field: the value of the selected Option.
width (number or length, optional)
Width of the field (in grid cells or as a length). Default for a text field: ten times the font size, directly in a table cell the width of the cell. Check boxes and radio buttons are square unless height is given.

CSS

In CSS selectors, this command is called formfield. Attributes marked “CSS property” can also be set with CSS; the attribute on the command takes precedence unless the CSS declaration is marked !important. The section CSS for layout commands describes further properties, precedence and inheritance.

Example

<Stylesheet>
  formfield { border-bottom: 0.5pt solid; background-color: #eef }
</Stylesheet>
<Record element="data">
  <PlaceObject>
    <Textblock width="12cm">
      <Paragraph>
        <Value>Name: </Value>
        <Formfield name="customer.name" value="{@name}" width="6cm"
                   tooltip="Name of the customer"/>
      </Paragraph>
      <Paragraph>
        <Formfield type="checkbox" name="customer.newsletter"
                   tooltip="Subscribe to the newsletter"/>
        <Value> Send me the newsletter</Value>
      </Paragraph>
      <Paragraph>
        <Value>Payment: </Value>
        <Formfield type="radio" name="payment" value="invoice" checked="yes"/>
        <Value> invoice </Value>
        <Formfield type="radio" name="payment" value="card"/>
        <Value> credit card</Value>
      </Paragraph>
      <Paragraph>
        <Value>Country: </Value>
        <Formfield type="choice" name="customer.country" value="{@country}" width="4cm">
          <ForAll select="country">
            <Option value="{@code}"><Value select="."/></Option>
          </ForAll>
        </Formfield>
      </Paragraph>
    </Textblock>
  </PlaceObject>
</Record>

See also

PlaceObject, Td, Paragraph, Option