CodeIgniter Forums
form_validation with array field - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: form_validation with array field (/showthread.php?tid=33358)



form_validation with array field - El Forum - 08-24-2010

[eluser]kaejiavo[/eluser]
Hi,

i have a problem validating an array field.
Code:
$this->form_validation->set_rules('qty[]', 'quantity', 'required');

  foreach ($items as $item) {
    // input field qty[]
    $quantity = array(
        'name' => "qty[{$item->id}]",
    'id' => 'quantity',
    'value' => set_value("qty[{$item->id}]"),
    'maxlength' => '5',
    'size' => '5',
    'style' => '',
    );
    $this->data['form']['quantity'][$item->id] = form_input($quantity);
  }

I get the form fields and the POST array as desired.
Code:
$_POST['qty']      
Array
(
    [3] => 4
    [1] =>
)

My Problem is that it will validate only if _all_ array values are set. I need only at least 1 value set for the application.
Has someone a clue for me how to validate this?

TIA
Marco


form_validation with array field - El Forum - 08-24-2010

[eluser]coffeeandcode[/eluser]
This is exactly the issue I'm dealing with here. You might want to follow that thread as well.