*/ error_reporting(E_ALL); ini_set('display_errors', '1'); /** * Get Reform's class loader */ require_once '../reform/ClassLoader.php'; Reform\ClassLoader::register(); // faster than generic autoloaders use Reform\Reform; use Reform\ValidationRule\Required; use Reform\ValidationRule\Matches; /** * EXAMPLE FORM */ $form = Reform::form('')->append(array(Reform::input('name')->setAttribute('id', 'name')->addRule(new Required()), Reform::email('email')->addRule(new Required()), $password1 = Reform::password('password1')->addRule(new Required()), Reform::password('password2')->addRule(new Matches($password1)), Reform::select('account_type', array(Reform::option('Tier 1', 1), Reform::option('Tier 2', 2), Reform::option('Tier 3', 3), Reform::option('Tier 4', 4))), Reform::submit('', 'Sign up'))); // run validation !empty($_POST) && $form->runValidation(); //echo '<pre>'; print_r($form); echo '</pre>'; die(); ?> <style> body { color: #444; font: 14px Arial; } form { width: 250px; } label { display: block;
<?php use Reform\Reform; // get a few variables $name = $this->getAttribute('name'); $id = $this->getAttribute('id'); $label = $this->getLabel() == '' ? $name : $this->getLabel(); if (empty($id)) { $id = $name . '_field'; $this->setAttribute('id', $id); } // build field's label $output = Reform::label($label)->setAttribute('for', $id); // open tag $output .= '<' . $this->getTagName(); // write in attributes if (count($this->getAttributes()) > 0) { $output .= ' ' . $this->attributesToString(); } // self closing if ($this->isSelfClosing()) { echo $output . ' />'; } else { $output .= '>'; // print any child element this tag may have foreach ($this->getChildren() as $element) { $output .= $element; } // call her done $output .= '</' . $this->getTagName() . '>'; echo $output;