Example #1
0
 public function getHtmlElement()
 {
     $el = new Element('select', ['name' => $this->getName()]);
     foreach ($this->getConfig() as $value => $label) {
         $option = new Element('option', ['value' => $value]);
         $option->setText($label);
         if (strval($value) === strval($this->getValue())) {
             $option->setAttribute('selected', true);
         }
         $el->appendChild($option);
     }
     return $el;
 }
Example #2
0
 public function getHtmlElement()
 {
     $el = new Element('input', ['type' => 'number', 'name' => $this->getName(), 'value' => $this->getValue()]);
     if ($this->hasOption('min')) {
         $el->setAttribute('min', $this->getOption('min'));
     }
     if ($this->hasOption('max')) {
         $el->setAttribute('max', $this->getOption('max'));
     }
     if ($this->hasOption('step')) {
         $el->setAttribute('step', $this->getOption('step'));
     }
     return $el;
 }
Example #3
0
 public static function fromFile($path, $encoding = null, $html = false)
 {
     if ($html) {
         return HtmlElement::fromFile($path, $encoding);
     }
     return Element::fromFile($path, $encoding);
 }
Example #4
0
 public function getHtmlElement(array $attributes = null, $fieldCallback = null)
 {
     if ($fieldCallback !== null && !is_callable($fieldCallback)) {
         throw new \InvalidArgumentException("Argument 1 passed to buildHtml needs to be valid callback" . " or null");
     }
     $attributes = array_replace(['action' => '#', 'method' => Method::GET, 'enctype' => Type::X_WWW_FORM_URLENCODED], $attributes ? $attributes : []);
     $form = new Element('form', $attributes);
     foreach ($this->_fields as $field) {
         $el = $field->getHtmlElement();
         if ($fieldCallback) {
             $el = call_user_func($fieldCallback, $el);
         }
         $form->appendChild($el);
     }
     return $form;
 }
Example #5
0
 public function __construct($documentType = null, array $attributes = null, Node $parent = null, array $children = null)
 {
     parent::__construct('html', $attributes, $parent, $children);
     $this->_documentType = $documentType ? $documentType : DocumentType::HTML5;
 }