Welcome Guest, Not a member yet? Register   Sign In
array fields using form_validation
#1

[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.

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


So, I use My_Form_validation modified as follows.


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

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

Are there any other good ideas?
#2

[eluser]Aken[/eluser]
I would create a callback function or extend the validation class with your own rule(s).
#3

[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.
#4

[eluser]tpetrone[/eluser]


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.
#5

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


Code:
$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.

Thunks.




Theme © iAndrew 2016 - Forum software by © MyBB