Filters Example

$form = new Formagic();

// load filter class and create instance
Formagic::loadClass('Formagic_Filter_Replace');
$replace = new Formagic_Filter_Replace(array(
    's' => 'x',
    '.' => '...',
));

// assign filter to item
$form->addItem('input', 'myInput', array(
        'label' => 'Filtered text',
        'filters' => $replace,
    ))

    ->addItem('submit', 'mySubmit', array(
        'label' => 'Send'
    ));

// print form
if ($form->validate()) {
    echo '<p class="submitted">
        <strong>Form status:</strong><br />
        submitted
    </p>';
}

echo $form->render();

Result

Description

Assigned filters will be applied every time getValue() is called on an item. To get the unfiltered value, call getUnfilteredValue() on the item object.
To test the filter used in this example just enter “Stop shouting.” and see what happens.

Leave a Reply

Your email address will not be published. Required fields are marked *


*