Welcome Guest, Not a member yet? Register   Sign In
Get all Validation rules when submitting form
#1

[eluser]wooptoo[/eluser]
First of all I need to mention that I'm using codeigniter-restserver to create an API and an application on top of it.

I want to enable live form validation in my application, client-side, with javascript.

You know that when you submit a form, if some fields fail validation, it will give you the error messages for those fields.
What I would like is for CodeIgniter to give me all the validation messages for a certain field, not just one message at a time. For example if I have 'required|valid_email|is_unique[bla.bla]' for the email field, I'd have to submit it three times to get all validation messages.

Is this possible at all?
#2

[eluser]CroNiX[/eluser]
Not without some heavy extending of the Form Validation library. As soon as a rule fails it quits checking any more rules for that field as there is generally no point in running more rules if the field already failed one.

One user friendly thing you might do is have a javascript tip popup next to each field that explains the rules for the field to the user, telling them what's allowed, etc.
#3

[eluser]wooptoo[/eluser]
Yap, I'm already doing the tooltip thing (bootstrap popover is great for this). HTML5 validation would be better, but since it's not supported by every browser you can't really count on it (yet).

Well, I solved my problem by exposing a parsed version of the validation rules through the API.
#4

[eluser]Aken[/eluser]
You can't rely on HTML5 (or any front-end) validation only anyway, as it's easy to alter by anyone. Ideally you'd want both.
#5

[eluser]wooptoo[/eluser]
Of course I'm doing validation on the backend too. But you can't rely on html5 validation at all because the browsers that don't support it will not display any messages to the users.
#6

[eluser]Aken[/eluser]
Oh I know. But you'd be surprised how many people think HTML5 or JS alone is sufficient.




Theme © iAndrew 2016 - Forum software by © MyBB