displayHead( 'Example' ); require_once 'patForms.php'; require_once 'patErrorManager.php'; // normal elements definition - these will be added // to the form as usual. $elementsDefinition = array( 'username' => array( 'type' => 'String', 'attributes' => array( 'required' => 'yes', 'display' => 'yes', 'edit' => 'yes', 'label' => 'Username', 'description' => 'Enter your username here. Maximum length: [ELEMENT_MAXLENGTH]', 'default' => 'argh', 'maxlength' => '15', 'minlength' => '4', 'title' => 'Username', ), ), 'password' => array( 'type' => 'String', 'attributes' => array( "type" => "password", "required" => "yes", "display" => "yes", "edit" => "yes", "label" => "Password", "description" => "Enter your password here. Maximum length: [ELEMENT_MAXLENGTH]", "maxlength" => "15", "minlength" => "4", "title" => "Password", ), ), ); // definition of the group element itself - it does not need // that many attributes, as it is only a container element. $groupDefinition = array( 'display' => 'yes', 'label' => 'Basic Data', 'title' => 'Basic Data', 'description' => 'Basic authentication data', ); // definition of the area element which will be a part of the group $areaDefinition = array( 'required' => 'yes', 'display' => 'yes', 'edit' => 'yes', 'label' => 'Area', 'title' => 'Area', 'description' => 'Choose the area to access here.', 'values' => array( array( 'label' => 'Please choose an area...', 'value' => '', ), array( 'label' => 'Very pretty area', 'value' => 'a01', ), array( 'label' => 'No-nonsense area', 'value' => 'a02', ), ), ); // definition of the secure element which will be a part of the group $secureDefinition = array( 'required' => 'yes', 'display' => 'yes', 'edit' => 'yes', 'label' => 'Secure access', 'title' => 'Secure access', 'description' => 'Choose the area to access here.', 'clicklabel' => 'yes', 'value' => 'yes', 'id' => 'mySecure' ); // create the form $form =& patForms::createForm( $elementsDefinition, array( 'name' => 'myForm' ) ); $form->setNamespace('mynamespace'); // create the needed renderer $renderer =& patForms::createRenderer( "Array" ); // set the renderer $form->setRenderer( $renderer ); // create the group element $groupEl =& patForms::createElement( 'loginOptions', 'Group', $groupDefinition ); // give the group the needed renderer too - we can use // the same here $groupEl->setRenderer( $renderer ); // create the elements for the group $gel1 =& patForms::createElement( 'area', 'Enum', $areaDefinition ); $gel2 =& patForms::createElement( 'secure', 'Switch', $secureDefinition ); // now add the elements to the group $groupEl->addElement( $gel1 ); $groupEl->addElement( $gel2 ); // and add the group to the form $form->addElement( $groupEl ); // use auto-validation $form->setAutoValidate( 'save' ); /* $foo = $form->getElementByName('area'); echo $foo->serialize(); $bar = $form->getElementById('mySecure'); echo $bar->serialize(); */ // serialize the elements $elements = $form->renderForm(); // ERROR DISPLAY ------------------------------------------------------ // ask the form if it has been submitted and display errors. For // convenience and also to keep the examples easy to understand, all // the following examples will use teh helper methods of the examples // framework to display the errors and the form. if( $form->isSubmitted() ) { displayErrors( $form ); // see patExampleGen/customFunctions.php } // DISPLAY FORM ------------------------------------------------------ // output the opening form tag echo $form->serializeStart(); // display all elements foreach( $elements as $element ) { echo '
'; // a group acts like a form, so the group element's element // is actually a new array with a list of elements that have // been rendered each - we simply display them all too. // // NOTE: this is just to show you how the structure looks like! if( is_array( $element['element'] ) ) { echo '
'.$element['label'].''; foreach( $element['element'] as $subelement ) { echo '
'; echo $subelement['label']."
"; echo $subelement['element'].'
'; echo ''.$subelement['description'].'
'; } echo '
'; } // normal element else { echo $element['label']."
"; echo "
".$element["element"]."
"; if( isset( $element["description"] ) ) { echo "".$element["description"]."
"; } } echo '
'; } // submit button, closing form tag echo '

'; echo $form->serializeEnd(); // EXAMPLE END ------------------------------------------------------ $exampleGen->displayFooter(); echo '
' . wordwrap(htmlentities(print_r($form->getElement('loginOptions')->serialize(), true)), 200);
?>