form::select PHP Method

select() public static method

public static select ( $name, $options = [], $selected = null, $attributes = [] )
    public static function select($name, $options = array(), $selected = null, $attributes = array())
    {
        $attributes['name'] = $name;
        $html = array();
        foreach ($options as $value => $display) {
            if (is_array($display)) {
                $html[] = static::optgroup($display, $value, $selected);
            } else {
                $html[] = static::option($value, $display, $selected);
            }
        }
        return Html::element('select', implode('', $html), $attributes);
    }

Usage Example

Example #1
0
 public function action_create()
 {
     if ($this->user) {
         //cannot create new accounts when a user is logged in
         $this->action_index();
     }
     $post = $_POST;
     // Create a new user
     $user = ORM::factory('user')->values($post);
     if ($user->check()) {
         $user->save();
         // user  created, show login form
         $this->action_login();
     } else {
         //show form
         echo form::open();
         echo 'username:'******'username') . '<br>';
         echo 'password:'******'password') . '<br>';
         echo 'password confirm:' . form::password('password_confirm') . '<br>';
         echo 'role:' . form::select('role', array('user' => 'user', 'admin' => 'admin')) . '<br>';
         echo form::submit('create', 'create');
         echo form::close();
         echo Kohana::debug($user->validate()->errors());
     }
 }
All Usage Examples Of form::select