我已经为Agiletoolkit
mysql
建立了一个名为注册页面的用户注册页面和一个登录页面。如何在注册时检查注册页面上的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(动态)已经存在。
另一个问题是如何验证下拉菜单(如用户角色)以及如何在我的数据库表(客户表)中插入用户角色字段值。
答案 0 :(得分:0)
如果电子邮件为空或不为空,我已编写代码getElement('email') - > validateNotNull() - > validateField('filter_var($ this-> get(),FILTER_VALIDATE_EMAIL)') ; ?>我也用这段代码测试了api-> db-> dsql() - >表( '顾客') - >字段('email')//我想它也可以写成 - > count() - 化合物其中( '电子邮件',$形式 - >获得( '电子邮件')) - > do_getOne();
/* From Database Table*/
if(trim($form->get('email'))==trim($exist)){
throw $form->exception('This email is already exist')->setField('email');
}?> for the email is exit or not. It works fine in localhost, xampp but in server it shows an error with $this. And another thing is that I have write <?php $user_role_list=array(''=>'Please Select',1=>'Admin',2=>'Moder',3=>'User'); $this->addField('userrole')->setValueList($user_role_list);?> in module folder page And for userrole, I have to validate with the code like <?php $form->getElement('userrole')->validateNotNull();?> in page folder page.