Ejemplo n.º 1
0
 protected function elements($defaults)
 {
     $admin = rand(0, 1);
     $elements = array('username' => array('type' => 'text', 'required' => true, 'minlength' => 0), 'firstname' => array('type' => 'text', 'required' => true, 'minlength' => 2), 'middlename' => array('type' => 'text', 'title' => 'Middle name'), 'lastname' => array('type' => 'text', 'required' => true, 'minlength' => 2), 'password' => array('type' => 'text', 'required' => false), 'email' => array('type' => 'text', 'title' => 'E-mail', 'required' => true, 'minlength' => 0, 'validation' => 'email', 'error' => 'Invalid e-mail address, dude...', 'description' => Output::translate('Can be empty, but must otherwise be valid')), 'phone1' => array('type' => 'text', 'title' => 'Phone 1', 'required' => false), 'phone2' => array('type' => 'text', 'title' => 'Phone 2', 'required' => false), 'birthdate' => array('type' => 'date', 'required' => true, 'minlength' => 0, 'validation' => 'date'), 'group' => array('type' => 'dropdown', 'required' => true, 'options' => \app\models\Category::all('category_name <> ?', ''), 'validation' => 'options'), 'secret' => array('type' => 'text'), 'oele' => array('type' => 'text'), array('always' => true, 'require' => array('phone1', 'phone2'), 'validation' => function ($form) {
         if (!$form->input('phone1') && !$form->input('phone2')) {
             return 'Must enter at least 1 phone number';
         }
     }, 'fields' => 'phone1, phone2'), array('require' => array('phone1'), 'validation' => 'phoneNumber', 'fields' => 'phone1'), array('require' => array('phone2'), 'validation' => 'phoneNumber', 'fields' => 'phone2'));
     if (!$admin) {
         unset($elements['secret']);
     }
     return $elements;
 }
Ejemplo n.º 2
0
 protected function elements($defaults)
 {
     $this->options->oninput = 'this.op.value=this.username.value;';
     return array(array('type' => 'markup', 'inside' => function ($form) {
         return 'Username: <output name="op" xoninput="alert(this);this.value=this.form.username.value;">...</output>';
     }), 'username' => array('type' => 'text', 'required' => true, 'minlength' => 2, 'validation' => function ($form) {
         $db = $form->application->db;
         $usernameExists = models\User::count(array('username' => $form->input('username')));
         return $usernameExists ? 'This username is taken' : true;
     }, 'description' => Output::translate('Have you read our %1?', array(Output::ajaxLink(Output::translate('username guidelines', null, array('ucfirst' => false)), 'blog/page/username')))), 'password' => array('type' => 'password', 'required' => true, 'minlength' => 0), 'color' => array('title' => 'Favourite colour', 'type' => 'colour', 'required' => true, 'minlength' => 2, 'default' => 'white'), 'category' => array('title' => 'Favourite blog category', 'type' => 'options', 'options' => \app\models\Category::all('category_name <> ?', ''), 'dummy' => '-- I have not the favourite', 'validation' => function ($form, $name) {
         if ('' == $form->input($name, '')) {
             // Can be empty
             $form->output($name, null);
             return true;
         }
         return $form->validateOptions($form, $name);
     }), 'birthdate' => array('title' => 'When\'s your dob?', 'type' => 'date', 'required' => true, 'validation' => 'date', 'default' => 'YYYY-MM-DD'), 'bio' => array('type' => 'textarea', 'required' => true, 'minlength' => 0, 'rows' => 5, 'regex' => '.*\\w\\s\\w.*'), array('type' => 'markup', 'outside' => '<fieldset><legend>' . Output::translate('Options') . '</legend>'), 'stupid' => array('type' => 'checkbox', 'required' => true, 'name' => 'options[stupid]'), 'this' => array('type' => 'checkbox', 'name' => 'options[this]'), 'that' => array('type' => 'checkbox', 'name' => 'options[that]'), array('type' => 'markup', 'outside' => '</fieldset>'), 'email' => array('type' => 'email', 'required' => true, 'validation' => 'email', 'description' => Output::translate('Only used for account activation. <strong>We won\'t store this.</strong>')), 'gender' => array('type' => 'radio', 'required' => true, 'options' => array('m' => Output::translate('Male'), 'f' => Output::translate('Female'))), 'hobbies' => array('type' => 'checkboxes', 'options' => models\Category::all(), 'required' => true, 'minlength' => 2, 'name' => 'misc[hobbies][]'), array('type' => 'markup', 'outside' => '<fieldset><legend>Terms</legend>'), 'terms' => array('type' => 'checkbox', 'title' => Output::translate('I very much do agree on the terms yes yes'), 'description' => 'Do you really? Huh? <b>Well?? Do ya??</b>', 'required' => true), array('type' => 'markup', 'outside' => '</fieldset>'), array('validation' => function ($form) {
         return strlen($form->input('username')) <= strlen($form->input('password'));
     }, 'fields' => 'password', 'message' => 'Your password must be at least as long as your username'), array('require' => 'username', 'validation' => function ($form) {
         $usr = strtolower($form->input('username'));
         $clr = strtolower($form->input('color'));
         return !is_int(strpos($usr, $clr)) && !is_int(strpos($clr, $usr));
     }, 'fields' => array('username', 'color'), 'message' => 'Username cannot contain Colour and vice versa'));
 }
Ejemplo n.º 3
0
 protected function elements($defaults)
 {
     return array('password' => array('type' => 'password', 'description' => Output::translate('Admin password to prove you\'re one of the hims/hers.'), 'required' => true, 'minlength' => 4), 'prefs' => array('type' => 'grid', 'subtype' => 'checkbox', 'reverse' => true, 'title' => Output::translate('Choose categories'), 'horizontal' => array(Output::translate('Domain'), models\Domain::all('domain_id >= ?', $this->options->domain ? $this->options->domain->domain_id : 0)), 'vertical' => array(Output::translate('User'), models\User::all('user_id >= ?', $this->options->user ? $this->options->user->user_id : 0)), 'description' => Output::translate('One category per user / domain combination'), 'name' => 'options'), 'cat' => array('type' => 'options', 'options' => models\Category::all()));
 }
Ejemplo n.º 4
0
 protected function elements($defaults)
 {
     return array('username' => array('type' => 'text', 'required' => true, 'minlength' => 2, 'validation' => 'unique', 'unique' => array('model' => 'app\\models\\User', 'field' => 'username', 'conditions' => array('user_id <> ?', array($defaults->user_id))), 'description' => Output::translate('Have you read our %1?', array(Output::ajaxLink(Output::translate('username guidelines', null, array('ucfirst' => false)), 'blog/page/username')))), 'password' => array('type' => 'text', 'minlength' => 2, 'description' => Output::html(Output::translate('Current password: %1', array($defaults->password)))), 'full_name' => array('type' => 'text', 'required' => true, 'minlength' => 3), 'bio' => array('type' => 'textarea'), 'access' => array('type' => 'text', 'validation' => 'csv'), 'domains' => array('type' => 'text', 'validation' => 'csv', 'storage' => 'in_domains', 'description' => Output::translate('Comma (+ space) separated. Will be checked individually and created if no existo.')));
 }