What's a good strategy for repurposing an 'add new record' form for 'edit record' ? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: What's a good strategy for repurposing an 'add new record' form for 'edit record' ? (/showthread.php?tid=35204) |
What's a good strategy for repurposing an 'add new record' form for 'edit record' ? - El Forum - 10-22-2010 [eluser]stormbytes[/eluser] I've gotta build a form tomorrow for my CI-app. The app will have to 'add' new records as well as edit existing ones. I'm wondering if there's a simple, easy way to repurpose the same form? Off the top of my head, I'm guessing I'd have to add 'isset($_POST['field'] ? 'whatever' : ''" to each of the form's inputs so that I can 'flag' if it's in add-mode or in edit-mode. So I guess I'm looking for a second opinion here. Is this the right approach? Is there a better strategy? Something built-in CI that I haven't come across yet? Thanks for all the help peoples! What's a good strategy for repurposing an 'add new record' form for 'edit record' ? - El Forum - 10-22-2010 [eluser]wiredesignz[/eluser] Look at the form helper and what functionality it might provide to help you. What's a good strategy for repurposing an 'add new record' form for 'edit record' ? - El Forum - 10-22-2010 [eluser]stormbytes[/eluser] Hiya wiredesignz I actually did look at it - The only feature that might help in this regard is the set_value() function, but I guess what I'm looking for is a suggestion on how to use/apply it for what I'm trying to do, or some general advice on how to go about this task Cheers! What's a good strategy for repurposing an 'add new record' form for 'edit record' ? - El Forum - 10-22-2010 [eluser]Phil Sturgeon[/eluser] Nothing built in, just logic. Something I usually do to make things much quicker, is assign my validation rules to an array then loop through them and create a stdObject which I can pass to the form.php view file. Add Code: foreach($this->_validation_rules as $rule) Edit Code: foreach($this->_validation_rules as $rule) Then just pass that and use it in your forms. You could use set_value() instead, as long as you use it AFTER form_validation->run() has been called. What's a good strategy for repurposing an 'add new record' form for 'edit record' ? - El Forum - 10-22-2010 [eluser]stormbytes[/eluser] Phil - Pure Awesomeness! Read through much of the form validation class. Will do some homework tomorrow & give it a go. Thanks |