* @license LGPL, see license.txt for details * @link http://www.php-tools.net */ ?> formValidator example
"yes", "display" => "yes", "edit" => "no", "label" => "Username", "description" => "Enter your username here. Maximum length: [ELEMENT_MAXLENGTH]", "position" => "1", "accesskey" => "A", "default" => "argh", "maxlength" => "15", "minlength" => "4", "title" => "Username", "onchange" => "alert( pfe_username.getValue() );" ); $email = array( "required" => "yes", "display" => "yes", "edit" => "yes", "label" => "Email", "description" => "Enter your email address here.", "position" => "1", "accesskey" => "A", "default" => "argh@php-tools.net", "maxlength" => "50", "minlength" => "4", "format" => "email", "title" => "Email", "onchange" => "alert( pfe_email.getValue() );" ); // create the attributes collection for the element $pub = array( 'name' => 'publisher', 'required' => 'yes', 'display' => 'yes', 'edit' => 'yes', 'label' => 'Favorite publisher', 'description' => 'Choose your favorite comics publisher', 'position' => '1', 'accesskey' => 'p', 'values' => array( array( 'label' => 'Please choose...', 'value' => '' ), array( 'label' => 'DC Comics', 'value' => 'dc' ), array( 'label' => 'Marvel Comics', 'value' => 'marvel' ) ), "onchange" => "alert( pfe_publisher.getValue() );" ); // create the form - static function call $form = patForms::createForm(); // you can set default attributes $form->setDefaultAttributes( array( "style" => "width:100%;" ) ); $form->setAttribute( 'name', 'myForm' ); // set the mode of the form //$form->setMode( "readonly" ); // create needed elements $el1 = $form->createElement( "user", "String", $username ); $el2 = $form->createElement( "email", "String", $email ); $el3 = $form->createElement( 'publisher', 'Enum', $pub ); // add elements to the form as needed $form->addElement( $el1 ); $form->addElement( $el2 ); $form->addElement( $el3 ); // check if form has been saved if( isset( $_GET["save"] ) ) { // tell the element it has been submitted $form->setSubmitted( true ); // validate the element if( !$form->validateForm() ) { echo "patForms: validation failed. Errors:

"; $errors = $form->getValidationErrors(); foreach( $errors as $elementName => $elementErrors ) { if( empty( $elementErrors ) ) continue; echo 'Field: '.$elementName.''; echo "
";
	            print_r( $elementErrors );
	            echo "
"; } } else echo "patForms: validation successful.

"; } // create the needed renderer $renderer =& patForms::createRenderer( "Array" ); // set the renderer $form->setRenderer( $renderer ); // serialize the elements using the array renderer $elements = $form->renderForm(); echo $form->getScripts(); ?>
Generated elements "; echo "
".$element["element"]."
"; echo "".$element["description"]."

"; } ?>



Javascript output
getScripts() );
?>

Elements source code '; } ?>