public function __construct(array $attributes) { $this->setAttributes($attributes); parent::__construct(); // overwrite default value with value from POST array if (!empty($_POST) && isset($_POST[$this->getAttribute('name')])) { $this->setValue($_POST[$this->getAttribute('name')]); } }
public function __construct($attributes) { if (!is_array(attributes)) { $attributes = array('name' => (string) $attributes); } $this->setAttributes($attributes); parent::__construct(); // overwrite value with value from the post array if (!empty($_POST) && isset($_POST[$this->getAttribute('name')])) { $this->setValue($_POST[$this->getAttribute('name')]); } }
/** * Constructor * * @param string option's inner text * @param mixed array of attributes or just the value (as a string) * @return void **/ public function __construct($attributes = array()) { if (!is_array($attributes)) { $attributes = array('label' => $attributes); } if (array_key_exists('label', $attributes)) { $this->setLabel($attributes['label']); unset($attributes['label']); } $this->setAttributes($attributes); parent::__construct(); }
/** * Set Child Element * * @param mixed child element (object) or text node (string) * @param string Whether to position the new child before or after existing children * @return object Returns the current element (object) to allow method chaining **/ public function setChild($element, $position = 'bottom') { // you can't nest non-Option if (!$element instanceof Option) { throw new InvalidArgumentException('You cannot set anything other than Option as the child of Select.'); } parent::setChild($element, $position); // overwrite default value with value from POST array if (!empty($_POST) && isset($_POST[$this->getAttribute('name')])) { $this->setValue($_POST[$this->getAttribute('name')]); } return $this; }