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

[eluser]Jacob Graf[/eluser]
I am trying to use max_length[10] for some fields with form_validation and I keep getting the following error upon page load. If I remove all of the max_length checks, everything works great!

Code:
A PHP Error was encountered

Severity: Warning

Message: mb_strlen() expects parameter 1 to be string, array given

Filename: libraries/Form_validation.php

Line Number: 982

Here is an example of one of my rules...

Code:
array (
      'field' => 'city',
      'label' => 'City',
      'rules' => 'required|max_length[30]'
      ),
#2

[eluser]CodeIgniteMe[/eluser]
Did you pass a multidimentional array or just that simple array?
I believe you should pass it like this.
Code:
$config = array(
               array(
                     'field'   => 'city',
                     'label'   => 'City',
                     'rules'   => 'required|max_length[30]'
                  )
            );
$this->form_validation->set_rules($config);
#3

[eluser]Jacob Graf[/eluser]
Yes, I passed the multi-dimensional. I just posted one of the sub-arrays as an example.
#4

[eluser]CodeIgniteMe[/eluser]
Debug your array with var_dump() or print_r() before you set it to the validation rules
#5

[eluser]Jacob Graf[/eluser]
Here is the output from print_r. I only added the max_length back to the last_name field and verified it was throwing the error. I don't see anything out of place, do you?

Code:
Array
(
    [login] => Array
        (
            [0] => Array
                (
                    [field] => username
                    [label] => Username
                    [rules] => required
                )

            [1] => Array
                (
                    [field] => password
                    [label] => Password
                    [rules] => required
                )

        )

    [register] => Array
        (
            [0] => Array
                (
                    [field] => first_name
                    [label] => First Name
                    [rules] => required
                )

            [1] => Array
                (
                    [field] => last_name
                    [label] => Last Name
                    [rules] => required|max_length[20]
                )

            [2] => Array
                (
                    [field] => address_1
                    [label] => Address
                    [rules] => required
                )

            [3] => Array
                (
                    [field] => city
                    [label] => City
                    [rules] => required
                )

            [4] => Array
                (
                    [field] => state
                    [label] => State
                    [rules] => required|alpha|exact_length[2]
                )

            [5] => Array
                (
                    [field] => zip
                    [label] => Zip Code
                    [rules] => required|numeric|exact_length[5]
                )

            [6] => Array
                (
                    [field] => telephone
                    [label] => Telephone
                    [rules] => required
                )

            [7] => Array
                (
                    [field] => email_address
                    [label] => Email Address
                    [rules] => required|valid_email
                )

            [8] => Array
                (
                    [field] => shirt_size
                    [label] => Shirt Size
                    [rules] => required
                )

            [9] => Array
                (
                    [field] => username
                    [label] => Username
                    [rules] => required|callback_username_check
                )

            [10] => Array
                (
                    [field] => password
                    [label] => Password
                    [rules] => required|min_length[8]
                )

            [11] => Array
                (
                    [field] => pass_conf
                    [label] => Password Confirmation
                    [rules] => required|matches[password]
                )

        )

)
#6

[eluser]Jacob Graf[/eluser]
Anybody?
#7

[eluser]Aken[/eluser]
Does your run() function contain the group you're trying to use?
Code:
if ($this->form_validation->run('register') === false) ...




Theme © iAndrew 2016 - Forum software by © MyBB