Welcome Guest, Not a member yet? Register   Sign In
min_length and max_length being ignored
#1

[eluser]Sepix[/eluser]
Hello!

I have the problem that min_length and max_length is not working at all for me. It is not only that it doesn't create any Error Message, it just doesn't get called entirely. The form gets send without it being validated. I tested this by sending the form multiple times as well as placing Echo Code inside the min and max length function in the library. It seems like the functions are not executed. Other flags like "unique" work totally fine.

I have this problem with CI Versions 2.1.1 and 2.1.2 so far.

Just to make sure i didnt do anything wrong here are the code snippets of my test:


The Form Field:

Code:
<p>Test Name: &lt;input name="name" value="&lt;?php echo set_value('name'); ?&gt;"&gt;&lt;/p>


The Validation:

Code:
$this->form_validation->set_rules('name', 'Name', 'required|min_length[10]');


Does anyone else have the same problem?
#2

[eluser]Aken[/eluser]
Post your whole controller function.
#3

[eluser]Unknown[/eluser]
this is all new to me, are there any basic around here?
#4

[eluser]Sepix[/eluser]
[quote author="Aken" date="1341802474"]Post your whole controller function.[/quote]

Here you go:

Code:
function index()
    {
        $this->load->helper(array('form', 'url'));

        $this->load->library('form_validation');

        $this->form_validation->set_rules('name', 'Name', 'required|min_length[3]|max_length[36]|is.unique[users.name]');
        $this->form_validation->set_rules('password', 'Password', 'required|matches[passconf]');
        $this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
        $this->form_validation->set_rules('email', 'Email', 'required|matches[emailconf]|valid_email|is_unique[users.email]');
        $this->form_validation->set_rules('emailconf', 'Email Confirmation', 'required');

        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('registration');
        }
        else
        {
            $this->load->view('portal');
        }
    }

However this doesn't change much. All other flags are working without any problems so it cannot be a problem with the controller. The only things that do not work is min and max length.
#5

[eluser]Aken[/eluser]
Aside from the is_unique rule being wrong in the name field set_rules(), your controller looks fine from first glance. I just tested a fresh install of 2.1.2 and had no problems using min and max length.

I would add the type attribute to your input tag, even if it isn't 100% necessary.

Maybe, on a really off chance, your registration and portal views happen to have the same content? Like you copied one into the other and forgot to change it. Sometimes we make dumb mistakes like that.

Other than that, it might be specific to your application's environment for whatever reason. Best I can say is start a page from scratch and see if just the bare bare minimum doesn't work. If not, try and debug into the code and figure out why.
#6

[eluser]Sepix[/eluser]
Oh god i am an idiot.
I edited the wrong function the whole time. No wonder it did not work. -_-

To try out form validation i first created a separate controller for testing purposes before adding it to the place it belongs. While i changed the routing to the new function i changed the contents in the old controller instead of the new one...

I will go bang my head against the table for a few times now...

Thanks a lot and sorry for wasting your time.




Theme © iAndrew 2016 - Forum software by © MyBB