首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何检查电子邮件在Agiletoolkit框架和mysql中是否存在

如何检查电子邮件在Agiletoolkit框架和mysql中是否存在
EN

Stack Overflow用户
提问于 2013-11-23 20:31:27
回答 1查看 120关注 0票数 0

我已经为用户注册建立了一个名为sign up page的页面,并使用mysqlAgiletoolkit中建立了一个登录页面。如何在注册时在注册页面检查电子邮件是否存在于Agiletoolkit框架中?我已经尝试过这段代码

代码语言:javascript
复制
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表)中插入用户角色字段值。

EN

回答 1

Stack Overflow用户

发布于 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();

代码语言:javascript
复制
             /* 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. 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20162330

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档