Welcome Guest, Not a member yet? Register   Sign In
What's a good strategy for repurposing an 'add new record' form for 'edit record' ?
#1

[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!
#2

[eluser]wiredesignz[/eluser]
Look at the form helper and what functionality it might provide to help you.
#3

[eluser]stormbytes[/eluser]
Hiya wiredesignz Smile

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!
#4

[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)
{
    $channel->{$rule['field']} = $this->input->post($rule['field']);
}

Edit

Code:
foreach($this->_validation_rules as $rule)
{
    if($this->input->post($rule['field']) !== FALSE)
    {
        $channel->{$rule['field']} = $this->input->post($rule['field']);
    }
}

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.
#5

[eluser]stormbytes[/eluser]
Phil -

Pure Awesomeness!

Read through much of the form validation class. Will do some homework tomorrow & give it a go.

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB