Welcome Guest, Not a member yet? Register   Sign In
Validation with an array
#1

[eluser]Felipe Diesel[/eluser]
Hi,

I was playing with CodeIgniter for a while and now I started my real first project.

Usually I use inputs like this:
Code:
<input name="person[name]" type="text" />
<input name="person[address]" type="text" />
So when the form is submitted I have an array in $_POST["person"]. But I got a problem when I try to use the Validation Class with this because the class just support "direct fields".

There's any way to make it works? Or I will need to leave the array scheme?

P.S.: I don't like the second choice because sometimes I have to submit data in different tables and I specify the table in the input field to do it more transparent.
#2

[eluser]Bulk[/eluser]
The built in validation library doesn't support that sort of validation by default no - if you're commited to that way of working you'll have to extend the validation library with something custom - or use callbacks.

But one note, if I'm reading your post correctly - you say you specify the database table to insert data in to as a field in the html? Bad idea. That presents a huge sql injection attack risk, not to mention in general exposing parts of your internal application to the world like that is generally considered bad form.

If I were you I would serious thought to finding a different approach to building your forms - CI gives you many different ways of working in that regard Smile
#3

[eluser]Felipe Diesel[/eluser]
I don't exactly use the table name, but I separate in arrays. So it become very easy to separate where any field must go.

Exist any class that let me define where the rules came from?

What ways CI give me?

PS.: I know my english sucks, but this is not my first language (I'm from Brazil).




Theme © iAndrew 2016 - Forum software by © MyBB