(c) drumrock, 2006
<html> <head> </head> <body> <?php require("./Drumrock_Smart_Form.class.php"); echo "<h1>Drumrock_Smart_Form class usage example</h1>"; echo "<h2>(for class version 0.1, 2006-07-30)</h2>"; echo "<h2>Creating new form with two elements</h2>"; echo "<p>(c) <a href='http://drumrock.ru/'>drumrock</a>, 2006</p>"; // Creating elements definitions $sf_elements = array(); // Array key is form element name as rendered // in HTML option 'name' of 'form' tag. $sf_elements['seconds'] = array( 'title' => "Seconds limit", // Element description text 'type' => "select", // element type 'values' => array( "default_value" => "30", "15" => "Small", "30" => "Medium", "45" => "Big" ), // Element's options values and their // descriptions. For elements without // predefined values, like text input, // for example, there must be empty array. // But also, if default value is needed // for any type of field, it must be // array element with 'default_value' key. // If no default value is specified, // for SELECT HTML-elements special // option '---' with empty value will // be rendered. 'validators' => array("external_validator") // External validation function(s) name(s) ); $sf_elements['events'] = array( 'title' => "Events count limit", 'type' => "input_text", 'values' => array('default_value' => "Hello, <world>!"), 'validators' => array("") ); // Creating class object $sf = new Drumrock_Smart_Form( "Test form", // Form title $sf_elements, // Form element's array "./", // Form action URL "POST" // Submit method (can be 'POST' or 'GET') ); // Renders initial form state echo $sf->get_html(); echo "<h2>Adding new element to the same form</h2>"; $sf->add_element('free_text', // Name of new element array( // Element parameters array 'title' => "Free-form text line", 'type' => "input_text", 'values' => array('default_value' => ""), 'validators' => array("") )); echo $sf->get_html(); echo "<h2>Inserting new element to the same form</h2>"; $sf->add_element('jailed_text', array( 'title' => "Jailed text line :-)", 'type' => "input_text", 'values' => array('default_value' => ":-)"), 'validators' => array("") ), 2 // Position to insert element at (starting from 0) ); echo $sf->get_html(); echo "<h2>Deleting element from form by element's name</h2>"; $sf->remove_element('events'); // Element's name (or elements' name if many) echo $sf->get_html(); // Validate submitted data width validation // functions specified in params while creating // form class object $sf->validate(); // Get list of validation errors as array $sf->get_validation_errors(); // Get HTML for errors' texts and form itself // with submitted data marked for correction // (maybe with red asterisks "*") $sf->get_html_with_validation_errors(); // Gets HTML for successfully processed (validated) // form $sf->get_success_html(); // Show myself :-) echo "<h2>Script itself</h2><pre>"; $prev_line = ""; foreach(@file("./index.php") as $line) if(!($prev_line == "" && trim($line) == "")) echo htmlspecialchars($line) . "\n"; echo "</pre>"; echo "<p>(c) <a href='http://drumrock.ru/'>drumrock</a>, 2006</p>"; ?> </body> </html>
(c) drumrock, 2006