• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Would like to condense some code.

#5
[eluser]mattpointblank[/eluser]
If I'm editing pre-populated values using the form_validation class, I do something like this:

Code:
$data['stuff'] = $this->Some_model->getStuff();

// then in my form view:

<input type="text" name="something" value="<?php echo set_value('something', $stuff['something']); ?>" />

This way, on first load, my page will show the database information, but if I modify it and submit the form again, it remembers my new value that was POSTed.

When I'm producing big, complex forms, I cheat a little and use the same form view to add and edit data. I use the above method, but add an @ sign in front of $stuff['something'] which means that in my controller, the edit() method can define $data['stuff'], but the add() one doesn't, and the error message is suppressed. It's a little hacky but it means that if I need to change my form, I don't have to modify it in two places (which gets complicated).


Messages In This Thread
Would like to condense some code. - by El Forum - 09-29-2009, 10:29 AM
Would like to condense some code. - by El Forum - 10-01-2009, 08:53 AM
Would like to condense some code. - by El Forum - 10-02-2009, 10:16 AM
Would like to condense some code. - by El Forum - 10-08-2009, 05:50 AM
Would like to condense some code. - by El Forum - 10-08-2009, 06:10 AM
Would like to condense some code. - by El Forum - 10-08-2009, 07:01 AM
Would like to condense some code. - by El Forum - 10-08-2009, 08:30 AM
Would like to condense some code. - by El Forum - 10-09-2009, 06:42 AM
Would like to condense some code. - by El Forum - 10-09-2009, 09:35 AM
Would like to condense some code. - by El Forum - 10-09-2009, 12:27 PM
Would like to condense some code. - by El Forum - 10-09-2009, 01:19 PM
Would like to condense some code. - by El Forum - 10-09-2009, 02:51 PM
Would like to condense some code. - by El Forum - 10-09-2009, 05:41 PM
Would like to condense some code. - by El Forum - 10-09-2009, 05:44 PM
Would like to condense some code. - by El Forum - 10-11-2009, 12:37 PM
Would like to condense some code. - by El Forum - 10-11-2009, 12:47 PM
Would like to condense some code. - by El Forum - 10-11-2009, 02:58 PM
Would like to condense some code. - by El Forum - 10-13-2009, 08:31 AM
Would like to condense some code. - by El Forum - 10-14-2009, 10:02 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.