$form = new Formagic(); // switch to XHTML renderer - // referenced by name for this example $form->setRenderer('Xhtml'); // load class and create item instance in one step $subContainer = Formagic::createItem( 'container', 'subcontainer', array( 'label' => 'Sub-Container' )); $subContainer ->addItem('input', 'subInput', array( 'label' => 'Input in subcontainer', )) ->addItem('checkbox', 'subCheckbox', array( 'label' => 'Checkbox in subcontainer' )); // assign filter to item $form ->addItem($subContainer) ->addItem('input', 'myInput', array( 'label' => 'Input outside of subcontainer', )) ->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
You can either set a new renderer by providing it’s name (that it it’s class name without prefix). You may of course set a previously created renderer instance as well. For this example we switched from default HTML table renderer to XHTML fieldset renderer.