Welcome Guest, Not a member yet? Register   Sign In
Pre-populating form data question
#1

[eluser]dignityandshame[/eluser]
So I have a form that submits data to an Oracle database. It works fine. Now I'm wanting to allow users to update the database using the same form (if possible). What is the best way to do this with CI? I've looked around the forums a bit and it looks like people are using the form validation class somehow, but I don't quite understand it at the moment.

Is it possible to use the same view to add and update records to a database or would it be better to have a separate view for each? I would think the former is better than the latter.

Some simple examples would be greatly appreciated. Thanks!
#2

[eluser]Eric Barnes[/eluser]
I am not sure if this helps but I use one view, controller, and model for all my forms.

For the View I use form.php and include the form which sends to one controller. Then I define an action in the form: <input type="hidden" name="action" value="<?php echo $action; ?>" />

For the controller that takes the data I use:

function submit()
{
$action = $this->input->post('action', TRUE);
if($action=='modify')
{
//must be modifying
}
else
{
//must be adding data
}
}

Then inside the if else I process the data and send it to the model to insert or update.

Hope that helps.




Theme © iAndrew 2016 - Forum software by © MyBB