Welcome Guest, Not a member yet? Register   Sign In
Setting Default Form Values with Validation and Post Variables
#1

[eluser]Minus[/eluser]
Although my question is code related, it's more of a conceptual issue I'm having trouble wrapping my head around.

I've been doing more work with CI and forms and have ran into something I'm sure there is an easy way to handle, I'm just missing it Smile

I'm building out a simple CRUD app. When designing the "edit" state to perform an update, I build out a form using the CI form helpers (I create an array in my controller and pass the variables to the view). The form helper array takes a value parameter that I can easily set to be whatever value I pull from the DB. Simple enough.

When I want to perform an insert and have a "new" item to add with my CRUD, I set my value to check the POST variable of the field so that if validation fails, the value the user entered becomes "sticky".

My issue is how do I combine these two things? I want to set a default or base value for my field, but if/when the user edits it (it then becomes the POST value) and needs to be returned (vs. the original value I set).

Is there an easy way to do this? Am I missing something? Smile

For smaller forms I've done something like checking to see if POST is set and then assigning that value to my value field otherwise use the default value. This doesn't seem ideal and when you have bigger forms doesn't scale well.

Any help or thoughts would be appreciated.

-Minus


Messages In This Thread
Setting Default Form Values with Validation and Post Variables - by El Forum - 08-15-2011, 01:27 PM



Theme © iAndrew 2016 - Forum software by © MyBB