Welcome Guest, Not a member yet? Register   Sign In
Validating multidimensional arrays
#1

I have two fields, named title[1] and title[2].
Quote:Indexes are used to mention the language id.


When I use this;

Code:
$this->form_validation->set_rules("title[]", "Menu title", "required");

It only validates the first index but not second or others using CodeIgniter 2.2.1. I want to know is there any fix so CI its self check for all the indexes and apply the same rule. Just like set_value["title[]"] reloads the value for each field automatically.


Regards Smile
Reply
#2

Hi,

CodeIgniter 2.2.1 is very buggy compared to the latest stable release. There have been huge improvements to CI since the 2.x branch. Perhaps you should consider upgrading?

However, in the meantime, if the array method is not working then perhaps you can run through the values in the array, setting a validation rule for each value in your own loop. That would then perhaps validate all the values in your array in the normal way, avoiding any potential bugs, if it is a bug.

Hope that helps,

Best wishes,

Paul


Here are some bug fixes from the changelog to encourage an upgrade:
Fixed a bug (#79) - Form Validation Library didn’t properly validate array fields that use associative keys or have custom indexes
Fixed a bug (#1624) - Form Validation Library rule matches didn’t property handle array field names.
Fixed a bug (#113) - Form Validation Library didn’t properly handle empty fields that were specified as an array.

Take a look at all the great stuff in CI3:
https://www.codeigniter.com/userguide3/changelog.html
Reply
#3

Thanks Paul,

Yes I agree, I think I should upgrade the version of CI and yes your solution is worked for me Smile (solved current problem) but rather than writing more code it is time to upgrade my CI to 3.x for upcoming projects!

Once again thanks for your time!
Reply
#4

(10-20-2015, 09:02 PM)PaulD Wrote:
Quote:Hi,

CodeIgniter 2.2.1 is very buggy compared to the latest stable release. There have been huge improvements to CI since the 2.x branch. Perhaps you should consider upgrading?

However, in the meantime, if the array method is not working then perhaps you can run through the values in the array, setting a validation rule for each value in your own loop. That would then perhaps validate all the values in your array in the normal way, avoiding any potential bugs, if it is a bug.

Hope that helps,

Best wishes,

Paul


[quote pid='324441' dateline='1445400167']

Here are some bug fixes from the changelog to encourage an upgrade:
Fixed a bug (#79) - Form Validation Library didn’t properly validate array fields that use associative keys or have custom indexes
Fixed a bug (#1624) - Form Validation Library rule matches didn’t property handle array field names.
Fixed a bug (#113) - Form Validation Library didn’t properly handle empty fields that were specified as an array.

Take a look at all the great stuff in CI3:
https://www.codeigniter.com/userguide3/changelog.html

Thanks Paul,


Yes I agree, I think I should upgrade the version of CI and yes your solution is worked for me Smile (solved current problem) but rather than writing more code it is time to upgrade my CI to 3.x for upcoming projects!

Once again thanks for your time!

[/quote]
Reply




Theme © iAndrew 2016 - Forum software by © MyBB