Beispiel #1
0
 /**
  * Parses the html for this date field.
  *
  * @return	string
  * @param	SpoonTemplate[optional] $template	The template to parse the element in.
  */
 public function parse($template = null)
 {
     // name is required
     if ($this->attributes['name'] == '') {
         throw new SpoonFormException('A name is required for a date field. Please provide a valid name.');
     }
     // start html generation
     $output = '<input type="text" value="' . $this->getValue() . '"';
     // add attributes
     $output .= $this->getAttributesHTML(array('[id]' => $this->attributes['id'], '[name]' => $this->attributes['name'], '[value]' => $this->getValue())) . ' />';
     // template
     if ($template !== null) {
         $template->assign('txt' . SpoonFilter::toCamelCase($this->attributes['name']), $output);
         $template->assign('txt' . SpoonFilter::toCamelCase($this->attributes['name']) . 'Error', $this->errors != '' ? '<span class="formError">' . $this->errors . '</span>' : '');
     }
     return $output;
 }
Beispiel #2
0
 /**
  * Parses the html for this textarea.
  *
  * @return	string
  * @param	SpoonTemplate[optional] $template	The template to parse the element in.
  */
 public function parse($template = null)
 {
     // name is required
     if ($this->attributes['name'] == '') {
         throw new SpoonFormException('A name is requird for a textarea. Please provide a valid name.');
     }
     // start html generation
     $output = '<textarea';
     // add attributes
     $output .= $this->getAttributesHTML(array('[id]' => $this->attributes['id'], '[name]' => $this->attributes['name'], '[value]' => $this->getValue()));
     // close first tag
     $output .= '>';
     // add value
     $output .= str_replace(array('"', '<', '>'), array('&quot;', '&lt;', '&gt;'), $this->getValue());
     // end tag
     $output .= '</textarea>';
     // template
     if ($template !== null) {
         $template->assign('txt' . SpoonFilter::toCamelCase($this->attributes['name']), $output);
         $template->assign('txt' . SpoonFilter::toCamelCase($this->attributes['name']) . 'Error', $this->errors != '' ? '<span class="formError">' . $this->errors . '</span>' : '');
     }
     return $output;
 }
Beispiel #3
0
 /**
  * Parses the html for this dropdown.
  *
  * @return	string
  * @param	SpoonTemplate[optional] $template	The template to parse the element in.
  */
 public function parse($template = null)
 {
     // name is required
     if ($this->attributes['name'] == '') {
         throw new SpoonFormException('A name is required for a dropdown menu. Please provide a name.');
     }
     // name?
     if (!$this->single) {
         $this->attributes['name'] .= '[]';
     }
     // init var
     $selected = $this->getSelected();
     // start html generation
     $output = "\r\n" . '<select';
     // add attributes
     $output .= $this->getAttributesHTML(array('[id]' => $this->attributes['id'], '[name]' => $this->attributes['name']));
     // end select tag
     $output .= ">\r\n";
     // default element?
     if (count($this->defaultElement) != 0) {
         // create option
         $output .= "\t" . '<option value="' . $this->defaultElement[1] . '"';
         // multiple
         if (!$this->single) {
             // if the value is within the selected items array
             if (is_array($selected) && count($selected) != 0 && in_array($this->defaultElement[1], $selected)) {
                 $output .= ' selected="selected"';
             }
         } else {
             // if the current value is equal to the submitted value
             if ($this->defaultElement[1] == $selected && $selected !== null) {
                 $output .= ' selected="selected"';
             }
         }
         // end option
         $output .= '>' . $this->defaultElement[0] . "</option>\r\n";
     }
     // loop all values
     foreach ($this->values as $label => $value) {
         // skip the default element
         if (isset($this->defaultElement[1]) && $this->defaultElement[1] == $label) {
             continue;
         }
         // value is an optgroup?
         if ($this->optionGroups[$label]) {
             // create optgroup
             $output .= "\t" . '<optgroup label="' . $label . '">' . "\n";
             // loop value
             foreach ($value as $key => $option) {
                 // create option
                 $output .= "\t\t" . '<option value="' . $key . '"';
                 // multiple
                 if (!$this->single) {
                     // if the value is within the selected items array
                     if (is_array($selected) && count($selected) != 0 && in_array($key, $selected)) {
                         $output .= ' selected="selected"';
                     }
                 } else {
                     // if the current value is equal to the submitted value
                     if ($key == $selected) {
                         $output .= ' selected="selected"';
                     }
                 }
                 // add custom attributes
                 if (isset($this->optionAttributes[(string) $key])) {
                     // loop each attribute
                     foreach ($this->optionAttributes[(string) $key] as $attrKey => $attrValue) {
                         // add to the output
                         $output .= ' ' . $attrKey . '="' . $attrValue . '"';
                     }
                 }
                 // end option
                 $output .= ">{$option}</option>\r\n";
             }
             // end optgroup
             $output .= "\t" . '</optgroup>' . "\n";
         } else {
             // create option
             $output .= "\t" . '<option value="' . $label . '"';
             // multiple
             if (!$this->single) {
                 // if the value is within the selected items array
                 if (is_array($selected) && count($selected) != 0 && in_array($label, $selected)) {
                     $output .= ' selected="selected"';
                 }
             } else {
                 // if the current value is equal to the submitted value
                 if ($this->getSelected() !== null && $label == $selected) {
                     $output .= ' selected="selected"';
                 }
             }
             // add custom attributes
             if (isset($this->optionAttributes[(string) $label])) {
                 // loop each attribute
                 foreach ($this->optionAttributes[(string) $label] as $attrKey => $attrValue) {
                     // add to the output
                     $output .= ' ' . $attrKey . '="' . $attrValue . '"';
                 }
             }
             // end option
             $output .= ">{$value}</option>\r\n";
         }
     }
     // end html
     $output .= "</select>\r\n";
     // parse to template
     if ($template !== null) {
         $template->assign('ddm' . SpoonFilter::toCamelCase(str_replace('[]', '', $this->attributes['name'])), $output);
         $template->assign('ddm' . SpoonFilter::toCamelCase(str_replace('[]', '', $this->attributes['name'])) . 'Error', $this->errors != '' ? '<span class="formError">' . $this->errors . '</span>' : '');
     }
     return $output;
 }
 /**
  * Parses the html for this dropdown.
  *
  * @return	string
  * @param	SpoonTemplate[optional] $template	The template to parse the element in.
  */
 public function parse($template = null)
 {
     // name required
     if ($this->name == '') {
         throw new SpoonFormException('A name is required for checkbox. Please provide a name.');
     }
     // loop values
     foreach ($this->values as $value => $label) {
         // init vars
         $name = 'chk' . SpoonFilter::toCamelCase($this->name);
         $element = array();
         $element[$name] = '<input type="checkbox" name="' . $this->name . '[]" value="' . $value . '"';
         // checked status
         if (in_array($value, $this->getChecked())) {
             $element[$name] .= ' checked="checked"';
         }
         // add attributes
         $element[$name] .= $this->getAttributesHTML($value, array('[id]' => $this->variables[$value]['id'], '[value]' => $value));
         // add variables to this element
         foreach ($this->variables[$value] as $variableKey => $variableValue) {
             $element[$variableKey] = $variableValue;
         }
         // end input tag
         $element[$name] .= ' />';
         // clone into element
         $element['element'] = $element[$name];
         // add checkbox
         $checkboxes[] = $element;
     }
     // template
     if ($template !== null) {
         $template->assign(SpoonFilter::toCamelCase($this->name, '_', true), $checkboxes);
         $template->assign('chk' . SpoonFilter::toCamelCase($this->name) . 'Error', $this->errors != '' ? '<span class="formError">' . $this->errors . '</span>' : '');
     }
     return $checkboxes;
 }
Beispiel #5
0
 /**
  * Parses the html for this hidden field.
  *
  * @return	string
  * @param	SpoonTemplate[optional] $template	The template to parse the element in.
  */
 public function parse($template = null)
 {
     // start html generation
     $output = '<input type="hidden" value="' . $this->getValue() . '"';
     // build attributes
     $attributes = array();
     if (isset($this->attributes['id'])) {
         $attributes['[id]'] = $this->attributes['id'];
     }
     $attributes['[name]'] = $this->attributes['name'];
     $attributes['[value]'] = $this->getValue();
     // add attributes
     $output .= $this->getAttributesHTML($attributes) . ' />';
     // parse hidden field
     if ($template !== null) {
         $template->assign('hid' . SpoonFilter::toCamelCase($this->attributes['name']), $output);
     }
     return $output;
 }
Beispiel #6
0
 /**
  * Parse the html for this button.
  *
  * @return	string
  * @param	SpoonTemplate[optional] $template	The template to parse the element in.
  */
 public function parse($template = null)
 {
     // start element
     $output = '<input type="' . $this->type . '" value="' . SpoonFilter::htmlspecialchars($this->value) . '"';
     // add attributes
     $output .= $this->getAttributesHTML(array('[id]' => $this->attributes['id'], '[name]' => $this->attributes['name'], '[value]' => $this->getValue())) . ' />';
     // parse
     if ($template !== null) {
         $template->assign('btn' . SpoonFilter::toCamelCase($this->attributes['name']), $output);
     }
     return $output;
 }