Welcome Guest, Not a member yet? Register   Sign In
Logic Question: How are you inserting a record and then showing it back to user?
#1

[eluser]Chad Crowell[/eluser]
I have a job site I'm working on, and trying to decide the best way to flow this part of the app:

1. Fill out form to add a job (jobs/add)
2. Insert job into db (jobs/insert)
3. Redirect using redirect() after successful insert to jobs/review

This works fine, but the user sees the url flash to the insert function and then onto the review page. Maybe a little disconcerting.

So I tried eliminating jobs/insert and placing the insert in the controller on the review function. This is nice because once the user submit the job, they are immediately shown the review page (assuming the insert, now in the review function, goes OK), but if for some reason they reload the review page, it will perform the insert again.

Ideas? Workarounds?
#2

[eluser]xwero[/eluser]
The simplest way to insert is to return back to the form, jobs/add in your case. And when the job is inserted successful you redirect before any content is outputted.

Almost straight from the user guide
Code:
function index()
    {
        $this->load->helper(array('form', 'url'));
        
        $this->load->library('validation');
                
        if ($this->validation->run() == FALSE)
        {
             // error things
        }
        else
        {
            // do insert
                    redirect('jobs/review');
        }

                $this->load->view('myform');
    }

What is the reasoning behind putting the insert code in another method?
#3

[eluser]drewbee[/eluser]
In this case you have two options.

1) is to redirect away from the post data. I would recomend creating a page for viewing the data of a record. Redirect to this after inserting, giving some message that it has been created and it is below.

2) my option by choice is to use a tokenizer so that even though the forms post data is submitted twice, it will only actually perform validation / actions once.




Theme © iAndrew 2016 - Forum software by © MyBB