• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
array fields using form_validation

[eluser]Yoshiyuki Mikome[/eluser]
Hi, everyone.

I have some array fields and I wish validate them using form_validation.

However, Codeigniter is only to return the following message, I can not know that an error in the position in the array.

$error["fieldname[]"] = "message"

So, I use My_Form_validation modified as follows.

if ( ! isset($this->_error_array[$row['field']]))
  if ($row['is_array'])
    eval('$this->_error_array["'.join('"]["', $row['keys']).'"][$cycles] = $message;');
    $this->_error_array[$row['field']] = $message;

I want to avoid copying of large functions, such as _excecute.

Are there any other good ideas?

I would create a callback function or extend the validation class with your own rule(s).

[eluser]Yoshiyuki Mikome[/eluser]
Then, I must create a function of each time, or I shall be prepared in advance of all the validation method.

Thanks for your reply.


Can't you validate each $fieldname['value'] ?

Looks like the user guide says you can validate the $fieldname[] , why not the $fieldname['value'] ?

If this work then you can validate each key=>value in the array.

Might work.

[eluser]Yoshiyuki Mikome[/eluser]
I have understood it.
It required a number of rules same as the array!.

$this->form_validation->set_rules('name[0]', '', 'required');
$this->form_validation->set_rules('name[1]', '', 'required');

Even though the number of arrays to change, Oh my god!

I have attempt to automatically generate both the HTML5 form and validation table from the same definition table.
Hmm, I will consider a little more a good way without rewriting the system code.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.