Axiom (v1.2.0)

A lightweight PHP framework
H:/Workspace/php-axiom/www/php-axiom/libraries/axiom/axFormHelper.class.php
Go to the documentation of this file.
00001 <?php
00017 class axFormHelper extends axBaseHelper {
00018 
00023     protected $_form_lines = array();
00024     
00029     protected $_form_fieldsets = array();
00030     
00038     public function __construct ($url = '', $method = 'post', $enctype = null) {
00039         parent::__construct ('form', array('action' => $url, 'method' => $method));
00040         if ($enctype)
00041             $this->setEnctype($enctype);
00042     }
00043 
00055     public function addLine ($name, $display_name = null, $type = "text", $value = "", $class = "") {
00056         $this->appendChild($this->_form_lines[$name] = axFormLineHelper::export($name, $display_name, $type, $value, $class));
00057         return $this;
00058     }
00059     
00066     public function getLine ($name) {
00067         return isset($this->_form_lines[$name]) ? $this->_form_lines[$name] : null;
00068     }
00069     
00076     public function setErrors (array $names) {
00077         foreach ($names as $index => $name) {
00078             if ($line = $this->getLine($name)) {
00079                 $line->setClass($line->getClass() ? $line->getClass() . ' error' : 'error');
00080                 unset($names[$index]);
00081             }
00082         }
00083         
00084         if (empty($names))
00085             return $this;
00086         
00087         foreach ($this->_fieldsets as $fieldset)
00088             $fieldset->setErrors($names);
00089         
00090         return $this;
00091     }
00092     
00100     public function addFieldset ($legend = "") {
00101         return $this->appendChild($this->_fieldsets[] = axFieldsetHelper::export($legend));
00102     }
00103     
00112     public function autoFill ($desc) {
00113         foreach ($this->_children as &$node) {
00114             if ($node instanceof axFieldsetHelper) {
00115                 $node->autoFill($desc);
00116             }
00117             if ($node instanceof Helper) {
00118                 $name = $node->getName();
00119                 if ($desc instanceof axModel && isset($desc->$name)) {
00120                     $value = $desc->$name;
00121                 }
00122                 elseif (is_array($desc) && isset($desc[$name])) {
00123                     $value = $desc[$name];
00124                 }
00125                 else {
00126                     continue;
00127                 }
00128                 
00129                 if ($node->getType() == 'radio' || $node->getType() == 'checkbox') {
00130                     if ($node->getValue() == $value)
00131                         $node->setChecked("checked");
00132                 }
00133                 else {
00134                     $node->setValue($value);
00135                 }
00136                 
00137                 unset($name);
00138             }
00139         }
00140         return $this;
00141     }
00142     
00149     public static function export ($url = '', $method = 'post', $enctype = null) {
00150         return new self ($url, $method, $enctype);
00151     }
00152 }
 All Data Structures Files Functions Variables