Пример #1
0
 public function index()
 {
     $profiler = new Profiler();
     $foods = array('tacos' => array('tacos', FALSE), 'burgers' => array('burgers', FALSE), 'spaghetti' => array('spaghetti (checked)', TRUE), 'cookies' => array('cookies (checked)', TRUE));
     $form = new Forge(NULL, 'New User');
     // Create each input, following this format:
     //
     //   type($name)->attr(..)->attr(..);
     //
     $form->hidden('hideme')->value('hiddenz!');
     $form->input('email')->label(TRUE)->rules('required|valid_email');
     $form->input('username')->label(TRUE)->rules('required|length[5,32]');
     $form->password('password')->label(TRUE)->rules('required|length[5,32]');
     $form->password('confirm')->label(TRUE)->matches($form->password);
     $form->checkbox('remember')->label('Remember Me');
     $form->checklist('foods')->label('Favorite Foods')->options($foods)->rules('required');
     $form->dropdown('state')->label('Home State')->options(locale_US::states())->rules('required');
     $form->dateselect('birthday')->label(TRUE)->minutes(15)->years(1950, date('Y'));
     $form->submit('save')->value('Save');
     if ($form->validate()) {
         echo Kohana::debug($form->as_array());
     }
     echo $form->render();
     // Using a custom template:
     // echo $form->render('custom_view', TRUE);
     // Inside the view access the inputs using $input_id->render(), ->label() etc
     //
     // To get the errors use $input_id_errors.
     // Set the error format with $form->error_format('<div>{message}</div>');
     // Defaults to <p class="error">{message}</p>
     //
     // Examples:
     //   echo $username->render(); echo $password_errors;
 }
Пример #2
0
 public function login()
 {
     if (Auth::instance()->logged_in()) {
         $this->template->title = 'User Logout';
         $form = new Forge('auth_demo/logout');
         $form->submit('Logout Now');
     } else {
         $this->template->title = 'User Login';
         $form = new Forge();
         $form->input('username')->label(TRUE)->rules('required|length[4,32]');
         $form->password('password')->label(TRUE)->rules('required|length[5,40]');
         $form->submit('Attempt Login');
         if ($form->validate()) {
             // Load the user
             $user = ORM::factory('user', $form->username->value);
             if (Auth::instance()->login($user, $form->password->value)) {
                 // Login successful, redirect
                 url::redirect('auth_demo/login');
             } else {
                 $form->password->add_error('login_failed', 'Invalid username or password.');
             }
         }
     }
     // Display the form
     $this->template->content = $form->render();
 }