Welcome Guest, Not a member yet? Register   Sign In
Form Validation
#1

[eluser]hkboateng[/eluser]
Hello everyone, I am writing validation for my form and it seems not for work. I have done it before but I not know why is not working with these form.
Code:
public function signup_validation()
    {
        $this->load->library('form_validation');
        
        $this->form_validation->set_rules('username', 'Username','required|max_length[15]|min_length[6]|xssclean|callback_validate_credentials');
        $this->form_validation->set_rules('password', 'Password','required|min_length[6]');
        
        $this->form_validation->set_rules('firstname', 'First Name','required|alpha|trim');
        $this->form_validation->set_rules('lastname', 'Last Name','required|alpha|trim');
        $this->form_validation->set_rules('username', 'Username','required|max_length[15]|min_length[6]|xss_clean|trim');
        $this->form_validation->set_rules('password', 'Password','required|min_length[6]|alpha_dash|trim');
        $this->form_validation->set_rules('confirmpwd', 'Confirm Password','required|matches[password]|trim');
        $this->form_validation->set_rules('email', 'Email Address','required|valid_email|is_unique[users.email]|trm');
        $this->form_validation->set_rules('city', 'City','required|alpha|trm');
        $this->form_validation->set_rules('state', 'State','required|alpha|trm');
        $this->form_validation->set_rules('country', 'Country','required|alpha|trim');
        
        $this->form_validation->set_message('is_unique', "Email Address already exits");
      
        //Loading Security helper
        if ($this->form_validation->run())
        {
            echo "An activation code has been sent to your email.";
        }
        else
{
     redirect('blog/signup');
}
    }

Can someone let me know what am doing wrong. Thanks
#2

[eluser]noslen1[/eluser]
In your validation rules, you have "trm" instead of "trim" for your email, city, and state rules, you also have "xssclean" instead of "xss_clean" in your username rule.

Don't know if that's what's blocking your app.
#3

[eluser]hkboateng[/eluser]
Thanks.. but I changed all the errors but is still not working. Is bypassing the validation rules to the if/else statements.

#4

[eluser]noslen1[/eluser]
What do you mean by "not working" ? Do you get the echo when not validated, or get redirected when validated ?
What data did you try to insert ?

Be more explicit please.
#5

[eluser]hkboateng[/eluser]
What I mean not working is, when the form in empty or if I type if a text to test the validation, it redirect to another page (as if false) but I wanted the validation to be printed on the form and not redirect to the failure page.
#6

[eluser]noslen1[/eluser]
Ohh, then just load your form view, without redirection, and display your errors in your form, for each field with something like that :
Code:
if (form_error('username')) :
    echo '<p class="error">'.form_error('username').'</p>';
endif;
#7

[eluser]jojo777[/eluser]
Have you checked if the callback 'callback_validate_credentials' is working properly.

In adition if the $this->form_validation->run() check returns false...

Code:
if ($this->form_validation->run()) {
echo 'cool!';
}else{
$this->load->view('myview');
}

Remember set in the view echo form_error for every field in the form.
Say if it works.
#8

[eluser]hkboateng[/eluser]
Thank guys.. I have been able to fix it.
#9

[eluser]jojo777[/eluser]
[quote author="hkboateng" date="1350982814"]Thank guys.. I have been able to fix it.[/quote]

Cool dude!

Anyway, what was the problem??




Theme © iAndrew 2016 - Forum software by © MyBB