function setUp()
 {
     $domParser = new SimpleForm_Dom_Parser();
     // create a simple input element
     $this->input = new SimpleForm_Dom_HtmlElement($domParser->parseElement('<input id="test" type="input" class="" value="meh"/>'));
     // create a label with an input in it
     $this->label = new SimpleForm_Dom_HtmlElement($domParser->parseElement('<label>Input Field:<input id="test" />(optional)</label>'));
 }
예제 #2
0
 public function parse($html)
 {
     $parser = new SimpleForm_Dom_Parser();
     $element = $parser->parseElement($html);
     // only support top level form tags for the minute
     if ($element->tagName != 'form') {
         throw new SimpleForm_Exception("Top level tag must be a form");
     }
     // only support forms with identifiers
     if (!$element->hasAttribute('id')) {
         throw new SimpleForm_Exception("Form must have an identifier");
     }
     $this->_form = $element;
     $this->_doc = $element->ownerDocument;
     $this->_xpath = new DomXPath($this->_doc);
     $this->_elements = array();
     $this->_labels = array();
     // go through form elements, build them
     foreach (array('input', 'select', 'textarea') as $tag) {
         foreach ($this->_doc->getElementsByTagName($tag) as $el) {
             // remove the submit marker to prevent outputting it again
             if ($el->getAttribute('name') == SimpleForm_Form::SUBMIT_MARKER) {
                 $el->parentNode->removeChild($el);
             } else {
                 $formEl = $this->_createFormElement($el);
                 $hash = $formEl->getHash();
                 $this->_elements[$hash] = $formEl;
             }
         }
     }
     // go through each label, build them
     foreach ($this->_doc->getElementsByTagName('label') as $el) {
         $formEl = $this->_createLabelElement($el);
         $hash = $formEl->getHash();
         $this->_labels[$hash] = $formEl;
     }
 }
 function _createSelectElement($html = '<select/>')
 {
     $parser = new SimpleForm_Dom_Parser();
     return new SimpleForm_Dom_Select($parser->parseElement($html));
 }
 /**
  * Creates an input element
  */
 function _createInputElement($html = '<input/>')
 {
     $parser = new SimpleForm_Dom_Parser();
     return new SimpleForm_Dom_Input($parser->parseElement($html));
 }
 function setUp()
 {
     $parser = new SimpleForm_Dom_Parser();
     $this->element = new SimpleForm_Dom_Textarea($parser->parseElement('<textarea name="testelement" id="testid">' . 'this is a value' . '</textarea>'));
 }