Esempio n. 1
0
 /**
  * Build the form element.
  */
 protected function build_form_element()
 {
     /* FIXME: Form id's should be unique, even if a form is rendered twice.
      * Perhaps a global cache of used form id's should be kept, and '-2'
      * suffixes added as needed? */
     assert('$this->_form instanceof AnewtForm; // Form renderer must have a AnewtForm instance');
     /* Default attributes */
     $id = $this->_form->_get('id');
     $attributes = array('method' => $this->_form->get('method-as-string'), 'action' => $this->_form->_get('action'), 'id' => $id);
     /* Encoding type */
     if ($this->_form->_contains_file_upload_control()) {
         $attributes['enctype'] = 'multipart/form-data';
     }
     /* Class name */
     if ($this->_form->_isset('class')) {
         $attributes['class'] = $this->_form->_get('class');
     }
     /* Output <form> element with all hidden elements */
     $form = new AnewtXHTMLForm(null, $attributes);
     /* The HTML DTD does not allow <input> elements as direct childs of
      * a <form> element. Use a <fieldset> that is completely hidden from
      * view instead. */
     $hidden_controls_fieldset = new AnewtXHTMLFieldset();
     $hidden_controls_fieldset->set_attribute('style', 'display: none;');
     foreach ($this->_form->_hidden_controls() as $hidden_control) {
         $hidden_controls_fieldset->append_child($hidden_control->build_widget());
     }
     $form->append_child($hidden_controls_fieldset);
     return $form;
 }
Esempio n. 2
0
 /**
  * Build XHTML for a fieldset
  *
  * \param $fieldset
  *   An AnewtFormFieldset instance.
  */
 protected function _build_fieldset_node($fieldset)
 {
     $fieldset_node = new AnewtXHTMLFieldset();
     $id = $fieldset->_get('id');
     if (!is_null($id)) {
         $fieldset_node->set_attribute('id', $id);
     }
     $class = $fieldset->_get('class');
     if (!is_null($class)) {
         $fieldset_node->set_attribute('class', $class);
     }
     $label = $fieldset->_get('label');
     if (!is_null($label)) {
         $legend_node = new AnewtXHTMLLegend();
         $legend_node->append_child($label);
         $fieldset_node->append_child($legend_node);
     }
     $fieldset_node->append_child($this->_build_description_node($fieldset));
     $fieldset_node->append_child($this->_build_error_node($fieldset));
     foreach (array_keys($fieldset->_children) as $key) {
         $fieldset_node->append_child($this->_build_child_node($fieldset->_children[$key]));
     }
     return $fieldset_node;
 }