CodeIgniter Forums
Validation Rules and non-primitive Form Fields - 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: Validation Rules and non-primitive Form Fields (/showthread.php?tid=5473)



Validation Rules and non-primitive Form Fields - El Forum - 01-22-2008

[eluser]Unknown[/eluser]
I am developing this application where there will a handful fields on the form that needs to be dynamically generated, some thing like these:
...
URL 1 Text: <input type="text" name="data[url][text][]">
URL 1 Link: <input type="text" name="data[url][link][]">

URL 2 Text: <input type="text" name="data[url][text][]">
URL 2 Link: <input type="text" name="data[url][link][]">

URL 3 Text: <input type="text" name="data[url][text][]">
URL 3 Link: <input type="text" name="data[url][link][]">

URL 4 Text: <input type="text" name="data[url][text][]">
URL 4 Link: <input type="text" name="data[url][link][]">

URL 5 Text: <input type="text" name="data[url][text][]">
URL 5 Link: <input type="text" name="data[url][link][]">
...

Those are dynamically generated DOM elements by Javascript as the number of URL links are indefinite. However, it doesn't see that CodeIgniter is capable of handling non-primitive type fields, as the Validation::run() cannot handle multi-dimention array when it parse through the validation rules.

A quick and dirty work-around I could come up is to use flat-out field names:
like
URL 1 Text: <input type="text" name="data_url_text_1">
URL 1 Link: <input type="text" name="data_url_url_1">

URL 2 Text: <input type="text" name="data_url_text_2">
URL 2 Link: <input type="text" name="data_url_url_2">

URL 3 Text: <input type="text" name="data_url_text_3">
URL 3 Link: <input type="text" name="data_url_url_3">

URL 4 Text: <input type="text" name="data_url_text_4">
URL 4 Link: <input type="text" name="data_url_url_4">

URL 5 Text: <input type="text" name="data_url_text_5">
URL 5 Link: <input type="text" name="data_url_url_5">

But that's very tiresome and error-prone. So is there anybody have any other thoughts to work around this issue?

Thanks!