field() 공개 메소드

echo $this->form->field('name'); echo $this->form->field('present', array('type' => 'checkbox')); echo $this->form->field(array('email' => 'Enter a valid email')); echo $this->form->field(array('name','email','phone'), array('div' => false));
public field ( mixed $name, array $options = [] ) : string
$name mixed The name of the field to render. If the form was bound to an object passed in `create()`, `$name` should be the name of a field in that object. Otherwise, can be any arbitrary field name, as it will appear in POST data. Alternatively supply an array of fields that will use the same options array($field1 => $label1, $field2, $field3 => $label3)
$options array Rendering options for the form field. The available options are as follows: - `'label'` _mixed_: A string or array defining the label text and / or parameters. By default, the label text is a human-friendly version of `$name`. However, you can specify the label manually as a string, or both the label text and options as an array, i.e.: `array('Your Label Title' => array('class' => 'foo', 'other' => 'options'))`. - `'type'` _string_: The type of form field to render. Available default options are: `'text'`, `'textarea'`, `'select'`, `'checkbox'`, `'password'` or `'hidden'`, as well as any arbitrary type (i.e. HTML5 form fields). - `'template'` _string_: Defaults to `'template'`, but can be set to any named template string, or an arbitrary HTML fragment. For example, to change the default wrapper tag from `
` to `
  • `, you can pass the following: `'{:label}{:input}{:error}
  • '`. - `'wrap'` _array_: An array of HTML attributes which will be embedded in the wrapper tag. - `list` _array_: If `'type'` is set to `'select'`, `'list'` is an array of key/value pairs representing the `$list` parameter of the `select()` method.
    리턴 string Returns a form input (the input type is based on the `'type'` option), with label and error message, wrapped in a `
    ` element.
    예제 #1
    0
    파일: Form.php 프로젝트: aniston/Platypus
     public function field($name, array $options = array())
     {
         if (isset($this->_binding) and is_numeric($this->_binding->{$name}) and abs($this->_binding->{$name}) <= 1.0E-5) {
             $options['value'] = '0';
         }
         if (!isset($options['wrap'])) {
             $options['wrap'] = array();
         }
         if (!isset($options['wrap']['class'])) {
             $options['wrap']['class'] = '';
         }
         $options['wrap']['class'] .= ' control-group';
         $errors = is_object($this->_binding) ? $this->_binding->errors() : array();
         if (isset($errors[$name])) {
             $options['wrap']['class'] .= ' error';
         }
         # Auto-populate select-box lists from validation rules
         if (isset($options['type']) and $options['type'] == 'select' and !isset($options['list'])) {
             $rules = $this->_binding->rules();
             if (isset($rules[$name])) {
                 if (is_array($rules[$name][0])) {
                     $rule_list = $rules[$name];
                 } else {
                     $rule_list = array($rules[$name]);
                 }
                 foreach ($rule_list as $rule) {
                     if ($rule[0] === 'inList' and isset($rule['list'])) {
                         foreach ($rule['list'] as $optval) {
                             $options['list'][$optval] = ucwords($optval);
                         }
                     }
                 }
             }
         }
         return parent::field($name, $options);
     }
    예제 #2
    0
     public function field($name, array $options = array())
     {
         if (is_array($name)) {
             return $this->_fields($name, $options);
         }
         list(, $options, $template) = $this->_defaults(__FUNCTION__, $name, $options);
         $meta = isset($this->schema) && is_object($this->schema) ? $this->schema->fields($name) : array();
         $defaults = array('label' => null, 'type' => isset($options['list']) ? 'select' : 'text', 'template' => $template, 'wrap' => array('class' => 'control-group'), 'list' => null);
         if (!empty($meta['required'])) {
             $defaults['required'] = true;
         }
         list($options, $field) = $this->_options($defaults, $options);
         if ($this->_binding) {
             $errors = $this->_binding->errors();
             if (isset($errors[$name])) {
                 $options['wrap']['class'] .= ' error';
             }
         }
         # Auto-populate select-box lists from validation rules or methods
         if ($options['type'] == 'select' && empty($options['list'])) {
             $options = $this->_autoSelects($name, $options);
         }
         return parent::field($name, $options);
     }