Exemplo n.º 1
0
 /**
  * Renders the HTML of the input.
  *
  * @param string Name of the field.
  * @param mixed Value for the field, can be a non valid value.
  * @param array Extra attributes to add to the input form (array())
  * @param array Extra choices (array())
  * @return string The HTML string of the input.
  */
 public function render($name, $value, $extra_attrs = array(), $choices = array())
 {
     $output = array();
     if ($value === null) {
         $value = '';
     }
     $final_attrs = $this->buildAttrs(array('name' => $name), $extra_attrs);
     $output[] = '<select' . Pluf_Form_Widget_Attrs($final_attrs) . '>';
     $groups = $this->choices + $choices;
     foreach ($groups as $option_group => $c) {
         if (!is_array($c)) {
             $subchoices = array($option_group => $c);
         } else {
             $output[] = '<optgroup label="' . htmlspecialchars($option_group, ENT_COMPAT, 'UTF-8') . '">';
             $subchoices = $c;
         }
         foreach ($subchoices as $option_label => $option_value) {
             $selected = $option_value == $value ? ' selected="selected"' : '';
             $output[] = sprintf('<option value="%s"%s>%s</option>', htmlspecialchars($option_value, ENT_COMPAT, 'UTF-8'), $selected, htmlspecialchars($option_label, ENT_COMPAT, 'UTF-8'));
         }
         if (is_array($c)) {
             $output[] = '</optgroup>';
         }
     }
     $output[] = '</select>';
     return new Pluf_Template_SafeString(implode("\n", $output), true);
 }
Exemplo n.º 2
0
 /**
  * Renders the HTML of the input.
  *
  * @param string Name of the field.
  * @param mixed Value for the field, can be a non valid value.
  * @param array Extra attributes to add to the input form (array())
  * @return string The HTML string of the input.
  */
 public function render($name, $value, $extra_attrs = array())
 {
     if ($value === null) {
         $value = '';
     }
     $final_attrs = $this->buildAttrs(array('name' => $name), $extra_attrs);
     return new Pluf_Template_SafeString(sprintf('<textarea%s>%s</textarea>', Pluf_Form_Widget_Attrs($final_attrs), htmlspecialchars($value, ENT_COMPAT, 'UTF-8')), true);
 }
Exemplo n.º 3
0
 /**
  * Renders the HTML of the input.
  *
  * @param string Name of the field.
  * @param mixed Value for the field, can be a non valid value.
  * @param array Extra attributes to add to the input form (array())
  * @return string The HTML string of the input.
  */
 public function render($name, $value, $extra_attrs = array())
 {
     if ($value === null) {
         $value = '';
     }
     $final_attrs = $this->buildAttrs(array('name' => $name, 'type' => $this->input_type), $extra_attrs);
     if ($value !== '') {
         $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
         $final_attrs['value'] = $value;
     }
     return new Pluf_Template_SafeString('<input' . Pluf_Form_Widget_Attrs($final_attrs) . ' />', true);
 }
Exemplo n.º 4
0
 /**
  * Renders the HTML of the input.
  *
  * @param string Name of the field.
  * @param array Value for the field, can be a non valid value.
  * @param array Extra attributes to add to the input form (array())
  * @param array Extra choices (array())
  * @return string The HTML string of the input.
  */
 public function render($name, $value, $extra_attrs = array(), $choices = array())
 {
     $output = array();
     if ($value === null) {
         $value = array();
     }
     $final_attrs = $this->buildAttrs(array('name' => $name . '[]'), $extra_attrs);
     $output[] = '<select multiple="multiple"' . Pluf_Form_Widget_Attrs($final_attrs) . '>';
     $choices = array_merge($this->choices, $choices);
     foreach ($choices as $option_label => $option_value) {
         $selected = in_array($option_value, $value) ? ' selected="selected"' : '';
         $output[] = sprintf('<option value="%s"%s>%s</option>', htmlspecialchars($option_value, ENT_COMPAT, 'UTF-8'), $selected, htmlspecialchars($option_label, ENT_COMPAT, 'UTF-8'));
     }
     $output[] = '</select>';
     return new Pluf_Template_SafeString(implode("\n", $output), true);
 }
Exemplo n.º 5
0
    /**
     * Renders the HTML of the input.
     *
     * @param string Name of the field.
     * @param mixed Value for the field, can be a non valid value.
     * @param array Extra attributes to add to the input form (array())
     * @return string The HTML string of the input.
     */
    public function render($name, $value, $extra_attrs = array())
    {
        if ($value === null) {
            $value = '';
        }
        $extra_config = '';
        if (isset($this->attrs['editor_config'])) {
            $_ec = $this->attrs['editor_config'];
            unset($this->attrs['editor_config']);
            $_st = array();
            foreach ($_ec as $key => $val) {
                if (is_bool($val)) {
                    if ($val) {
                        $_st[] = $key . ' : true';
                    } else {
                        $_st[] = $key . ' : false';
                    }
                } else {
                    $_st[] = $key . ' : "' . $val . '"';
                }
            }
            if ($_st) {
                $extra_config = ",\n" . implode(",\n", $_st);
            }
        }
        $final_attrs = $this->buildAttrs(array('name' => $name), $extra_attrs);
        // The special include for tinyMCE
        $out = '';
        if ($this->include_tinymce) {
            $out .= '<script language="javascript" type="text/javascript" src="' . $this->tinymce_url . '"></script>' . "\n";
        }
        $out .= '<script language="javascript" type="text/javascript">
	tinyMCE.init({
		mode : "' . $this->mode . '",
		theme : "' . $this->theme . '"' . $extra_config . '
	});
</script>';
        return new Pluf_Template_SafeString($out . sprintf('<textarea%s>%s</textarea>', Pluf_Form_Widget_Attrs($final_attrs), htmlspecialchars($value, ENT_COMPAT, 'UTF-8')), true);
    }