Пример #1
0
 function __construct($locator = null)
 {
     // get fieldeter object from controller
     $this->addField($field1 = new A_Model_Form_Field('field1'));
     $field1->addFilter(new A_Filter_Regexp('/[^0-9]/', ''));
     $field1->addRule(new A_Rule_Notnull('field1', 'Please enter Field 1'));
     $field1->addRule(new A_Rule_Range(1, 10, 'field1', 'Field 1 must be 1-10'));
     $field1->setType(array('renderer' => 'A_Html_Form_Select', 'values' => array(5, 10, 15), 'labels' => array('five', 'ten', 'fifteen')));
     $this->addField($field2 = new A_Model_Form_Field('field2'));
     $field2->addFilter(new A_Filter_Regexp('/[^0-9]/', ''));
     $field2->addRule(new A_Rule_Notnull('field2', 'Please enter Field 2'));
     $field2->addRule(new A_Rule_Match('field1', 'field2', 'Field 2 must match Field 1'));
     $field2->setType(array('renderer' => 'A_Html_Form_Text', 'size' => '10'));
     $this->addField($field3 = new A_Model_Form_Field('field3'));
     $field3->addFilter(new A_Filter_Regexp('/[^a-zA-Z]/', ''));
     $field3->addRule(new A_Rule_Length(5, 20, 'field3', 'Field 3 must be 5-20 characters'));
     // create fieldeter object then add it to the controller
     $this->addField($field4 = new A_Model_Form_Field('field4'));
     $field4->addFilter(new A_Filter_Regexp('/[^a-zA-Z]/', ''));
     $field4->addFilter(new A_Filter_ToUpper());
     //$field4->addRule(new A_Rule_Notnull('field4', 'Please enter Field 4'));
     $this->addRule(new A_Rule_Match('field3', 'field4', 'field 3 must match field 4'));
     //$this->excludeRules('field3');
     $this->addRule(new A_Rule_Notnull('field4', 'Please enter Field 4'));
 }
Пример #2
0
 public function index($locator)
 {
     $request = $locator->get('Request');
     $response = $locator->get('Response');
     $usersession = $locator->get('UserSession');
     $errmsg = '';
     $usernamestr = '';
     if (!$usersession->isLoggedIn()) {
         if ($request->get('op') == 'login') {
             $form = new A_Model_Form();
             $username = new A_Model_Form_Field('username');
             $username->addFilter(new A_Filter_Regexp('/[^a-zA-Z0-9]/', ''));
             $username->addFilter(new A_Filter_ToLower());
             $username->addRule(new A_Rule_Notnull('username', 'Username required'));
             $username->addRule(new A_Rule_Length(4, 20, 'username', 'Username must be 4 characters long'));
             $form->addField($username);
             $password = new A_Model_Form_Field('password');
             $password->addFilter(new A_Filter_Regexp('/[^a-zA-Z0-9\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)\\-\\_\\=\\+]/', ''));
             $password->addRule(new A_Rule_Notnull('password', 'Password required'));
             $password->addRule(new A_Rule_Length(4, 20, 'password', 'Password must be 4 characters long'));
             $form->addField($password);
             if ($form->isValid($request)) {
                 $user = $this->_load()->model('UsersModel');
                 if ($row = $user->findAuthorized($username->value, $password->value)) {
                     $usersession->merge($row);
                     $usersession->login($username->value, $password->value);
                 }
             } else {
                 $errmsg = 'Errors: ' . $form->getErrorMsg(', ');
                 $usernamestr = $username->value;
             }
         }
     }
     if ($usersession->isLoggedIn()) {
         $page_template = new A_Template_Strreplace('templates/logout.html');
     } else {
         $page_template = new A_Template_Strreplace('templates/login.html');
         $page_template->set('errmsg', $errmsg);
         $page_template->set('username', $usernamestr);
     }
     $response->setContent($page_template->render());
 }
Пример #3
0
 function index($locator)
 {
     $model = new A_Model_Form();
     // get fieldeter object from controller
     $model->addField($field1 = new A_Model_Form_Field('field1'));
     $field1->addFilter(new A_Filter_Regexp('/[^0-9]/', ''));
     $field1->addRule(new A_Rule_Notnull('field1', 'Please enter Field 1'));
     $field1->addRule(new A_Rule_Range(1, 10, 'field1', 'Field 1 must be 1-10'));
     $field1->setType(array('renderer' => 'A_Html_Form_Select', 'values' => array(5, 10, 15), 'labels' => array('five', 'ten', 'fifteen')));
     $model->addField($field2 = new A_Model_Form_Field('field2'));
     $field2->addFilter(new A_Filter_Regexp('/[^0-9]/', ''));
     $field2->addRule(new A_Rule_Notnull('field2', 'Please enter Field 2'));
     $field2->addRule(new A_Rule_Match('field1', 'field2', 'Field 2 must match Field 1'));
     $field2->setType(array('renderer' => 'A_Html_Form_Text', 'size' => '10'));
     $model->addField($field3 = new A_Model_Form_Field('field3'));
     $field3->addFilter(new A_Filter_Regexp('/[^a-zA-Z]/', ''));
     $field3->addRule(new A_Rule_Length(5, 20, 'field3', 'Field 3 must be 5-20 characters'));
     // create fieldeter object then add it to the controller
     $model->addField($field4 = new A_Model_Form_Field('field4'));
     $field4->addFilter(new A_Filter_Regexp('/[^a-zA-Z]/', ''));
     $field4->addFilter(new A_Filter_ToUpper());
     $field4->addRule(new A_Rule_Notnull('field4', 'Please enter Field 4'));
     $model->excludeRules('field3');
     //$model->run($locator);
     $request = $locator->get('Request');
     if ($model->isValid($request)) {
         echo 'DONE<br/><br/><a href="../">Return to Examples</a>';
     } else {
         if (!$model->isSubmitted()) {
             $model->set('field1', 15);
             $model->set('field2', 'init');
             $model->set('field3', 'init');
             $model->set('field4', 'init');
         }
         //dump($model);
         // create HTML form generator
         $form = new A_Html_Form();
         $form->setModel($model)->setWrapper('A_Html_Div', array('class' => 'fieldclass', 'style' => 'border:1px solid red;'))->select(array('name' => 'field1', 'values' => array(5, 10, 15), 'labels' => array('five', 'ten', 'fifteen'), 'id' => 'field1', 'label' => 'Field 1 (Numbers only in range 1-10)', 'after' => $field1->getErrorMsg(', ')))->text(array('name' => 'field2', 'id' => 'field2', 'label' => 'Field 2 (Must match Field 1)', 'after' => $field2->getErrorMsg(', ')))->text(array('name' => 'field3', 'id' => 'field3', 'label' => 'Field 3 (Letters only min length 5)', 'after' => $field3->getErrorMsg(', ')))->text(array('name' => 'field4', 'id' => 'field4', 'label' => 'Field 4 (Convert letters to uppercase)', 'after' => $field4->getErrorMsg(', ')))->submit('submit', 'Submit');
         echo $form->render();
         #			include 'templates/example_form2.php';
     }
 }
Пример #4
0
 function index($locator)
 {
     $session = $locator->get('Session');
     $user = $locator->get('UserSession');
     #dump($user, 'USER: '******'';
     $session->start();
     // controller and view use session
     $form = new A_Model_Form();
     $field = new A_Model_Form_Field('userid');
     $field->addRule(new A_Rule_Notnull('userid', 'User ID required'));
     $form->addField($field);
     $field = new A_Model_Form_Field('password');
     $field->addRule(new A_Rule_Notnull('password', 'Password required'));
     $form->addField($field);
     // If username and password valid and isPost
     if ($form->isValid($this->request)) {
         // How to translate URL in correct action variable?
         $model = $this->_load('app')->model('users');
         $userdata = $model->login($form->get('userid'), $form->get('password'));
         if ($userdata) {
             // user record matching userid and password found
             unset($userdata['password']);
             // don't save passwords in the session
             $user->login($userdata);
             $this->_redirect($locator->get('Config')->get('BASE') . 'login/');
             // build redirect URL back to this page
         } else {
             $errmsg = $model->getErrorMsg();
         }
     } elseif ($form->isSubmitted()) {
         // submitted form has errors
         $errmsg = $form->getErrorMsg(', ');
     }
     $template = $this->_load()->template();
     $template->set('errmsg', $errmsg);
     $template->set('userid', $form->get('userid'));
     $template->set('user', $user);
     $this->response->set('maincontent', $template);
 }
Пример #5
0
 public function setpassword($locator)
 {
     $request = $this->request;
     $usermodel = $this->_load('app')->model('users');
     $form = new A_Model_Form();
     $field = new A_Model_Form_Field('password');
     $field->addRule(new A_Rule_Notnull('password', 'Please fill in the password.'));
     $field2 = new A_Model_Form_Field('passwordagain');
     $field2->addRule(new A_Rule_Notnull('passwordagain', 'Please fill in the passwordagain.'));
     $form->addRule(new A_Rule_Match('passwordagain', 'password', 'Fields password and passwordagain do not match'));
     $form->addField($field);
     $form->addField($field2);
     if ($request->isPost()) {
         $resetkey = $request->get('resetkey');
         if ($form->isValid($this->request)) {
             $resetkey = $request->get('resetkey');
             $result = $usermodel->findResetkey($resetkey);
             if ($result === true) {
                 $usermodel->resetPassword($request->get('password'), $resetkey);
                 $this->response->setPartial('maincontent', 'user/password/resetpasswordsuccess');
             } else {
                 $this->response->setPartial('maincontent', 'user/password/resetpassworderror', array('message' => 'reset failed'));
             }
         } else {
             $this->response->setPartial('maincontent', 'user/password/resetpasswordform', array('message' => 'reset form invalid', 'resetkey' => $resetkey));
         }
     }
 }