Welcome Guest, Not a member yet? Register   Sign In
Using form validation with form field arrays??
#1

[eluser]minerbog[/eluser]
Hi All, Didn't realise how many people use CI! How cool is that!!

Anyway's to my problem,

I am trying to validate a repopulate a multilined form using form field arrays. However I cannot get CI to do it for love nor money. Single form fields are a piece of cake!

Code:
function _form_validate
{
$this->form_validation->set_rules('description[]', 'Description', 'my_alpha_numeric');
$this->form_validation->set_rules('qty[]', 'Qty', 'my_alpha_numeric');
}

I'm using the above code to validate the fields and it seems to be working. But when I try
Code:
set_value('description[]');
as indicated by the user guide, it just returns a default value??

Please help guys.
#2

[eluser]minerbog[/eluser]
And just one more thing. When setting validation rules with form field arrays the same validation will not allow spaces on a form field thats an array but will on a form field that isn't an array??

Any ideas??
#3

[eluser]Luis Perez[/eluser]
I think that you need an array index to validate each form element.

Code:
<?php
    // count all array elements and loop for each one...
    for($i=0; $i<count($this->input->post('description')); $i++) ){
        // ... set their own rules
        $this->form_validation->set_rules('description['.$i.']', 'Description', 'my_alpha_numeric');
    }
?&gt;

I guess that if there's no index, CI validates only one element.
#4

[eluser]minerbog[/eluser]
Thanks Luis, I'll give it a try




Theme © iAndrew 2016 - Forum software by © MyBB