我已经为用户注册建立了一个名为sign up page的页面,并使用mysql在Agiletoolkit中建立了一个登录页面。如何在注册时在注册页面检查电子邮件是否存在于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(动态)已经存在一样。
另一个问题是如何验证下拉菜单(如用户角色),以及如何在我的数据库表(customer表)中插入用户角色字段值。
发布于 2013-11-26 18:22:40
如果电子邮件为null或非null,我已经写了代码getElement('email')->validateNotNull()->validateField('filter_var($this->get(),FILTER_VALIDATE_EMAIL)');?>和我也测试过这个代码api->db->dsql() ->table('customer') ->field('email') //我猜它也可以写成->count() too ->where('email',$form->get('email')) ->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. https://stackoverflow.com/questions/20162330
复制相似问题