CodeIgniter Forums
DMZ validation check - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: DMZ validation check (/thread-32581.html)



DMZ validation check - El Forum - 07-27-2010

[eluser]frist44[/eluser]
I'm trying to use DMZ in my new application and I've hit a little speed bump. I worked out a registration page and everything was good because I would do a $obj->save() and validation would run. If something was wrong, I pass the obj to the view and the error message shows next to the field.

However, now I'm doing a save(), because this is for a "forgot password" page. So I want the user to input an email address. From that email, I look up a user account, and if valid, send that email their credentials. However, when I submit the form without an address, it doesn't go through validation. I looked at the $obj->validate() method, and I have a feeling that's what I'm supposed to go to, but can't figure it out. This is what I have so far.

Code:
public function index() {
        
        if (is_logged_in()) redirect(base_url());
        
        $u = new User();
        $data['obj'] = $u;
        $data['content_view'] = 'forgot_view';
        
        if (!is_submitted()) {
             $this->load->view('container_view', $data);
        } else {
            
            $u = new User();
            $u->email = $this->input->post('email');
            
            if ($u->validate()->get()) {            
                if ($u->exists()) {
                    // send forgot password email                
                                        
                    redirect_with_success(base_url(), 'flash_success_forgot');  
                } else {
                    redirect_with_error(base_url() . 'forgot', 'flash_error_forgot');
                }
            } else  {
                $this->load->view('container_view', $data);
            }
        }
    }



DMZ validation check - El Forum - 07-27-2010

[eluser]frist44[/eluser]
I figured it out. I missed that part of the manual. $u->validate() and then do a if($u->valid) check.


DMZ validation check - El Forum - 07-27-2010

[eluser]frist44[/eluser]
Is there a way to validate a select number of the fields?


DMZ validation check - El Forum - 09-07-2010

[eluser]bonatoc[/eluser]
are you using htmlform ?

http://www.overzealous.com/dmz/pages/validation.html#Custom.Rules

http://www.overzealous.com/dmz/pages/validation.html#Custom.Rules