Welcome Guest, Not a member yet? Register   Sign In
Form validation incorrect
#1

[eluser]blackwolf[/eluser]
Hi, I'm new in community sorry for my bad english I'm italian,
I hope to make you understand the problem
I have a problem with codeigniter form validation, I'm using version 1.6
I have some form fields with name and id such as 'fields[foo]', 'fields[bar]' etc..
If I set validation rules in my controller as the following code:
Code:
<?php
$rules['fields[foo]'] = 'required';
$rules['fields[bar]'] = 'required';
$this->validation->set_rules($rules);
?>
when I submit the form, validation errors appear even though I entered some values in the fields
What would I change in the code if I wrong?
Thanks
#2

[eluser]barbazul[/eluser]
For your example I'm assuming you have a form that goes something like this:

Code:
<input name="fields[foo]" />
<input name="fields[bar]" />

CI_Validation does not handle array-like inputs very nicely. why not changing your form to something like:

Code:
<input name="foo" />
<input name="bar" />

and the validation to:

Code:
<?php
$rules['foo'] = 'required';
$rules['bar'] = 'required';
$this->validation->set_rules($rules);
?>
#3

[eluser]blackwolf[/eluser]
Hi,Thanks for reply

So, I'm using array-like input because I cannot use normal field names for some reasons.
Before I'll go to insert data into database I must assign data to the model like :
Code:
<?php
$this->db->set('table', $_POST['fields']);
?>
I think that I'll add this feature to CI validation
#4

[eluser]sikkle[/eluser]
Give a look to validation extention build by the community somewhere in this forum about handling ARRAY validation.

good luck !




Theme © iAndrew 2016 - Forum software by © MyBB