Esempio n. 1
0
 /**
  * Renders the select widget to HTML.
  *
  * @param string $name    The name to use for the widget.
  * @param mixed  $value   The value to render into the widget.
  * @param array  $attrs   The attributes to use when rendering the widget.
  * @param array  $choices Additional choices to use for the select.
  *
  * @return string
  */
 public function render($name, $value, $attrs = null, $choices = null)
 {
     /**
      * Protect against null values.
      */
     if (is_null($value)) {
         $value = '';
     }
     /**
      * Finalize widget attributes.
      */
     $attrs = $this->buildAttrs(array('name' => $name), $attrs);
     /**
      * Add an array indicator to the name so PHP doesn't fail.
      */
     $attrs['name'] = $attrs['name'] . '[]';
     /**
      * Initialize output array.
      */
     $ouput = array();
     /**
      * Open the select tag.
      */
     $output[] = sprintf('<select multiple="multiple"%s>', DForms_Utils_Attributes::flatten($attrs));
     /**
      * Render the options.
      */
     $output[] = $this->renderOptions($choices, $value);
     /**
      * Close the select tag.
      */
     $output[] = '</select>';
     return implode("\n", $output);
 }
Esempio n. 2
0
 public function render($name, $value, $attrs = null)
 {
     if (is_null($value)) {
         $value = '';
     }
     $attrs = $this->buildAttrs(array('name' => $name), $attrs);
     return sprintf('<textarea%s>%s</textarea>', DForms_Utils_Attributes::flatten($attrs), htmlentities($value));
 }
Esempio n. 3
0
 /**
  * Renders the select widget to HTML.
  *
  * @param string $name    The name to use for the widget.
  * @param mixed  $value   The value to render into the widget.
  * @param array  $attrs   The attributes to use when rendering the widget.
  *
  * @return string
  */
 public function render($name, $value, $attrs = null)
 {
     if (is_null($value)) {
         $value = '';
     }
     $attrs = $this->buildAttrs(array('type' => $this->input_type, 'name' => $name), $attrs);
     if ($value != '') {
         $attrs['value'] = $value;
     }
     return sprintf('<input%s />', DForms_Utils_Attributes::flatten($attrs));
 }
Esempio n. 4
0
 public function tag()
 {
     if (array_key_exists('id', $this->attrs)) {
         $this->attrs['id'] = sprintf('%s_%s', $this->attrs['id'], $this->index);
     }
     $attrs = array('type' => 'radio', 'name' => $this->name, 'value' => $this->choice_value);
     $attrs = array_merge($this->attrs, $attrs);
     if ($this->isChecked()) {
         $attrs['checked'] = 'checked';
     }
     return sprintf('<input%s />', DForms_Utils_Attributes::flatten($attrs));
 }
Esempio n. 5
0
 /**
  * Renders the select widget to HTML.
  *
  * @param string $name    The name to use for the widget.
  * @param mixed  $value   The value to render into the widget.
  * @param array  $attrs   The attributes to use when rendering the widget.
  * @param array  $choices Additional choices to use for the select.
  *
  * @return string
  */
 public function render($name, $value, $attrs = null, $choices = null)
 {
     /**
      * Protect against null values.
      */
     if (is_null($value)) {
         $value = '';
     }
     /**
      * Finalize widget attributes.
      */
     $attrs = $this->buildAttrs(array('name' => $name), $attrs);
     /**
      * Initialize output array.
      */
     $ouput = array();
     /**
      * Open the select tag.
      */
     $output[] = sprintf('<select%s>', DForms_Utils_Attributes::flatten($attrs));
     /**
      * Render the options, passing value as an array since only one option
      * can be selected, but `renderOptions()` needs an array of selected
      * options.
      */
     $output[] = $this->renderOptions($choices, array($value));
     /**
      * Close the select tag.
      */
     $output[] = '</select>';
     return implode("\n", $output);
 }
Esempio n. 6
0
 /**
  * Renders the widget to HTML.
  *
  * @param string $name    The name to use for the widget.
  * @param mixed  $value   The value to render into the widget.
  * @param array  $attrs   The attributes to use when rendering the widget.
  *
  * @return string
  */
 public function render($name, $value, $attrs = null)
 {
     $attrs = $this->buildAttrs(array('type' => 'checkbox', 'name' => $name), $attrs);
     /**
      * Run the check test if it's a valid function.
      */
     if (is_callable($this->check_test)) {
         $result = $this->check_test($value);
     } else {
         /**
          * Take the boolean type casted value by default.
          */
         $result = (bool) $value;
     }
     /**
      * Add the checked attribute if the widget should be checked.
      */
     if ($result) {
         $attrs['checked'] = 'checked';
     }
     /**
      * Add a value attribute if the value is not a few predefined values.
      */
     if ($value !== '' && $value !== true && $value !== false && !is_null($value)) {
         $attrs['value'] = $value;
     }
     /**
      * Return the rendered widget.
      */
     return sprintf('<input%s />', DForms_Utils_Attributes::flatten($attrs));
 }
Esempio n. 7
0
 public function labelTag($contents = null, $attrs = null)
 {
     if (is_null($contents)) {
         $contents = htmlentities($this->label);
     }
     $widget = $this->field->widget;
     if (array_key_exists('id', $widget->attrs)) {
         $id = $widget->attrs['id'];
     } else {
         $id = $this->auto_id;
     }
     /**
      * If the ID is not null or an empty string.
      */
     if ($id) {
         if (is_null($attrs)) {
             $attrs = DForms_Utils_Attributes::flatten($attrs);
         }
         $contents = sprintf('<label for="%s"%s>%s</label>', $widget->idForLabel($id), $attrs, $contents);
     }
     return $contents;
 }