Containers Example

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

$subContainer
    ->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($subContainer)

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

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

        <strong>Form status:</strong>

        submitted

';
}

echo $form->render();

 

Result

 

Description

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 *


*