Containers Example

$subContainer = Formagic::createItem(
    'subcontainer', array(
        'rules' => 'mandatory'

    ->addItem('input', 'subInput', array(
        'label' => 'Input in subcontainer'
    ->addItem('checkbox', 'subCheckbox', array(
        'label' => 'Checkbox in subcontainer'

// assign filter to item
$form->addItem('input', 'myInput', array(
        'label' => 'Input outside of subcontainer',

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

// print form
if ($form->validate()) {
    echo '

        <strong>Form status:</strong>



echo $form->render();





Most properties you assign to a container will be inherited by it’s children, a mandatory rule for the example.
Containers can be nested in unlimited depth. Keep in mind that items of all containers are submitted at the same time: Nested containers do not open another form.

Leave a Reply

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