I have built up a page named sign up page for user registration and a login page in Agiletoolkit
with mysql
. How to check whether the email is existing in Agiletoolkit
Framework on the sign up page while registration? I have tried with this code
class page_signup extends Page {
function init(){
parent::init();
if($this->api->auth->isLoggedIn())$this->api->redirect('video');
//$user_role_list=array(' ',1=>'Admin',2=>'Moder',3=>'User');
$user_role_list=array(1=>'Admin',2=>'Moder',3=>'User');
$model=$this->add('Model_Customer');
$model->addField('password')->type('password')->mandatory(true);
$form = $this->add('MVCForm');
$form->setModel($model);
//$form->getElement('email')->validateNotNull()->validateField('filter_var($this->get(), FILTER_VALIDATE_EMAIL)');
$form->getElement('email')->validateNotNull()->validateField('filter_var($this->get(), FILTER_VALIDATE_EMAIL)');
$form->addField('password','confirm_password');
//$form->addField('dropdown','user role')->setValueList($user_role_list)->validateNotNull('Please Select User Role');
//$form->addField('dropdown','user role')->setValueList($user_role_list)->validateNotNull();
//$form->addField('dropdown','user role')->setValueList($user_role_list)->validateField('$this->get()==" "','Please select any one');
$form->addField('dropdown','user role')->setValueList($user_role_list);
$form->addSubmit();
$form->onSubmit(function($form){
//try{
/* */
$exist = $this->api->db->dsql()
->table('customer')
->field('count(*)') // I guess it can be written as ->count() too
->where('email',$model['email'])
->do_getOne();
if($exist[0]) {
throw $this->exception('Email year for this grant already exists')
->setField('email');
}
/* */
if($form->get('password') != $form->get('confirm_password'))
throw $form->exception('Passwords do not match')->setField('confirm_password');
$form->set('password',
$form->api->auth->encryptPassword($form->get('password'),$form->get('email')));
$form->update();
//$form->js()->hide('slow')->univ()->successMessage('Registered successfully')->execute();
$location = $_SERVER['PHP_SELF'];
$form->js()->hide('slow')->univ()->location($location)->successMessage('Registered successfully')->execute();
//$form->js()->univ()->dialogOK('Success','Registration is successful',$form->js()->_enclose()->univ()->location('/'))->execute();
/*}catch(Exception $e){
$form->js()->univ()->alert('Failed to add record')->execute();
}*/
});
}
}
It is not working properly. If the same email is given in the email text box by another user, then an error/alert will be shown like myemail(dynamic) is already existing.
Another question is how to validate a drop-down menu (like user role) and how to insert the user role filed value in my database table (customer table).