/**
  * Pre-process form: set id if needed and  and set
  */
 private function preProcessForm()
 {
     $xpath = new DOMXPath($this->document);
     $elements = $xpath->query('//input | //textarea | //div[@data-input-name]');
     /** @var DOMElement $element */
     foreach ($elements as $element) {
         // Set some basic vars
         $name = $element->getAttribute('name');
         if (!$name) {
             $name = $element->getAttribute('data-input-name');
         }
         if (!$name) {
             // At least a name is needed to submit a value.
             // Silently continue, might be a submit button.
             continue;
         }
         // Create an id if needed, this speeds up finding the element again
         $id = $element->getAttribute('id');
         if (!$id) {
             $id = md5(spl_object_hash($element));
             $element->setAttribute('id', $id);
         }
         $this->nameIdXref[$name] = $id;
         // Detect element type
         $type = $element->getAttribute('type');
         if ($element->tagName == 'textarea') {
             $type = 'textarea';
         }
         // Add validation
         if (isset($this->formElements[$type])) {
             $validator = new $this->formElements[$type]();
         } else {
             // Create a default validator
             $validator = new $this->formElements['text']();
         }
         if ($this->inputFilter->has($name)) {
             $input = $this->inputFilter->get($name);
         } else {
             // No input found for element, create a new one
             $input = new Input($name);
             // Enforce properties so the NotEmpty validator is automatically added,
             // we'll take care of this later.
             $input->setRequired(false);
             $input->setAllowEmpty(true);
             $this->inputFilter->add($input);
         }
         // Process element and attach filters and validators
         $validator($element, $input);
     }
 }