Welcome Guest, Not a member yet? Register   Sign In
Form validation in codeigniter does not seem DRY
#11

(This post was last modified: 10-25-2015, 04:11 PM by ignitedcms.)

Yeah ... I did like the idea of extending the callback function to accept more than one variable.

At the moment my form is quite complex in that it has a bunch of jquery options that show or hide input values depending on what option you pick. (To accommodate this I am having to use nested form_validation methods which is getting quite messy and difficult to read) I'm going to go away and spend a little time rethinking the validation process. When the form fails it needs to open/show the last div the user opens and repopulate it (which might not be a fixed number of input fields,they can ANY number as the user can add input fields dynamically on the client side), which I guess could be handled by passing a value into a jquery function in the footer to reshow that div.

It might even be a case of I'm trying to do too much in a single controller. I might end up writing separate controllers depending on what option the user picks and reloading separate views, for example have several form_open and form_closes on the one page instead of just the one.

In order to reduce the verbosity of the syntax and logic the form_validation codeigniter uses might not fit my needs but I will do some further testing.

To give you an idea, it's to do with ignitedCMS Pro when you dynamically choose your field types, depending on which field type you choose will show other options. It is definitely not as simple as validating a username which has only one reference field. Big Grin

http://recordit.co/ErScplTq0r

If anyone has anything further to add I'd be happy to hear.
Practical guide to IgnitedCMS - Book coming soon, www.ignitedcms.com
Reply
#12

The more we keep adding, the more complex your form seems to get Tongue
Reply
#13

(This post was last modified: 10-30-2015, 05:43 AM by ignitedcms.)

Hi Guys,

I've gone for storing the forms as a json array. For example a checkbox option will be
Code:
{"opt1":"name","opt2":"school"} ...yada yada
This makes it much more flexible and easier to return to the edit view if input was bad. Hopefully this will work out Big Grin
Practical guide to IgnitedCMS - Book coming soon, www.ignitedcms.com
Reply




Theme © iAndrew 2016 - Forum software by © MyBB