我已经建立了一个名为注册页面的用户注册页面和一个登录页面Agiletoolkit
。注册时如何在注册页面mysql
查看邮箱是否存在于Framework中?Agiletoolkit
我试过这个代码
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();
}*/
});
}
}
它无法正常工作。如果另一个用户在电子邮件文本框中提供了相同的电子邮件,则会显示错误/警报,例如 myemail(dynamic) 已存在。
另一个问题是如何验证下拉菜单(如用户角色)以及如何在我的数据库表(客户表)中插入用户角色字段值。