示例#1
0
 /**
  * Create a form input field.
  *
  * @param  string  $type
  * @param  string  $name
  * @param  string  $value
  * @param  array   $options
  * @return string
  */
 public static function input($type, $name, $value = null, $options = array())
 {
     //will implode all the options value and return as element attributes
     //$optionvalue = self::attributes($options);
     $optionvalue = JArrayHelper::toString($options);
     //assign the html
     $html = '';
     //swtich the type of input
     switch ($type) {
         // return text input
         case 'text':
             $html .= '<input type="text" name="' . $name . '" value="' . $value . '"  ' . $optionvalue . '    />';
             break;
             //return email input
         //return email input
         case 'email':
             $html .= '<input type="email" name="' . $name . '"  value="' . $value . '"  ' . $optionvalue . '    />';
             break;
             //return password input
         //return password input
         case 'password':
             $html .= '<input type="password"  name="' . $name . '" ' . $optionvalue . '  value="' . $value . '"     />';
             break;
             //return textarea input element
         //return textarea input element
         case 'textarea':
             $html .= '<textarea ' . $optionvalue . ' name="' . $name . '"  value="' . $value . '"     >' . $value . '</textarea>';
             break;
             //return file input element
         //return file input element
         case 'file':
             $html .= '<input type="file" name="' . $name . '" ' . $optionvalue . '  value="' . $value . '"     />';
             break;
             //return radio input element
         //return radio input element
         case 'radio':
             $id = isset($options['id']) && !empty($options['id']) ? $options['id'] : '';
             $html .= J2Html::booleanlist($name, $options, $value, $yes = 'JYES', $no = 'JNO', $id);
             break;
             //return checkbox element
         //return checkbox element
         case 'checkbox':
             $html .= '<input type="checkbox" ' . $optionvalue . '  value="' . $value . '"     />';
             break;
         case 'editor':
             break;
         case 'button':
             $html .= '<input type="button" name="' . $name . '"  ' . $optionvalue . '    value ="' . $value . '"';
             if (isset($options['onclick']) && !empty($options['onclick'])) {
                 $html .= '   onclick ="' . $options['onclick'] . '"';
             }
             $html .= '  />';
             break;
         case 'submit':
             $html .= '<input type="submit" name="' . $name . '"  ' . $optionvalue . 'value ="' . $value . '" />';
             break;
         case 'hidden':
             $html .= '<input type="hidden" name="' . $name . '" ' . $optionvalue . ' value ="' . $value . '" />';
             break;
         case 'file':
             $html .= '<input type="file" name="' . $name . '" value="' . $value . '" />';
             break;
     }
     return $html;
 }