Note that there are some explanatory texts on larger screens.

plurals
  1. POCodeIgniter: validating form array not working
    primarykey
    data
    text
    <p>I have an array of profile data I need to validate:</p> <pre><code>$user_group_profiles = $this-&gt;input-&gt;post('user_group_profiles', TRUE); foreach ($user_group_profiles as $key =&gt; $user_group_profile) { $this-&gt;form_validation-&gt;set_rules("user_group_profiles[$key][profile_name]", 'Profile Name', 'trim|required'); $this-&gt;form_validation-&gt;set_rules("user_group_profiles[$key][birthdate]", 'Birthdate', 'trim|required'); // TODO: heigth/weight not required, but the validation somehow makes it required $this-&gt;form_validation-&gt;set_rules("user_group_profiles[$key][height]", 'Height', 'trim|greater_than[0]'); $this-&gt;form_validation-&gt;set_rules("user_group_profiles[$key][weight]", 'Weight', 'trim|greater_than[0]'); } </code></pre> <p>Height and weight are option, but when no value is set for those fields, CI validation complains. A <code>var_dump($user_group_profiles);</code> shows this:</p> <pre><code>array 'ugp_b33333338' =&gt; array 'profile_name' =&gt; string '' (length=0) 'birthdate' =&gt; string '' (length=0) 'height' =&gt; string '' (length=0) 'weight' =&gt; string '' (length=0) </code></pre> <p>Any ideas what might be wrong?</p> <p>EDIT 1:</p> <p>I went into CI's Form_validation library and made <code>$_field_data</code> and public member. When I var_export it after, I got this:</p> <pre><code> 'user_group_profiles[ugp_833333338][height]' =&gt; array 'field' =&gt; string 'user_group_profiles[ugp_833333338][height]' (length=42) 'label' =&gt; string 'Height' (length=6) 'rules' =&gt; string 'greater_than[1]' (length=15) 'is_array' =&gt; boolean true 'keys' =&gt; array 0 =&gt; string 'user_group_profiles' (length=19) 1 =&gt; string 'ugp_833333338' (length=13) 2 =&gt; string 'height' (length=6) 'postdata' =&gt; string '' (length=0) 'error' =&gt; string 'The Height field must contain a number greater than 1.' (length=54) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload