Render a single element in a form

Nov 29, 2013
Render a single element in a form
  • In your form templates element's are rendered in the sub template default_group.php

    PHP:

    $this->elements;
     
    Is an array of element objects, keyed on the element name.
    By default the default_group.php sub template loops over the element's and renders them all out.

    Often in a custom template we want to get a specific element, so if I wanted to access the element named 'age' I could do:

    PHP:

    $ageElement = $this->elements['age'];
     
    Each element is an object with a series of properties:
    • plugin - the element's plugin e.g. 'field'
    • id - Unique reference, e.g. 'tablename___name'
    • element - the HTML field e.g. <input .... />
    • label_raw - the label as plain text
    • label - the label text wrapped in its <label/> tag
    • value - the value assigned to the element
    • error - any error message generated from a fail validation
    • column (fabrik 3.0 only) css used to build group columns
    To output the element's value we can write this PHP:
    PHP:

    echo $ageElement->value;