0

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).

thothal
  • 16,690
  • 3
  • 36
  • 71
ankan
  • 1
  • 4
  • You need to debug your logic and find out where it is failing or when you get unexpected results. Plus, your question isn't very specific and is more of a general "how do I make all this code work", which probably won't get much attention. – Jerico Sandhorn Nov 23 '13 at 13:21

1 Answers1

0

If email is null or not null for that I have write the code getElement('email')->validateNotNull()->validateField('filter_var($this->get(), FILTER_VALIDATE_EMAIL)'); ?> And I have also tested with this code api->db->dsql() ->table('customer') ->field('email') // I guess it can be written as ->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. 
ankan
  • 1
  • 4