Welcome Guest, Not a member yet? Register   Sign In
How to show a preview / confirmation page before writing the form to the database
#1

[eluser]thbt[/eluser]
I'm using the validation class to create and validate a lengthy form -- love the ease with which I can do form validation so far. Following the example in the documentation was easy.... However, the example writes the form data straight to the database. E.g.:

Code:
$this->load->helper(array('form', 'url'));
    $this->load->library('validation');
    $rules['username']    = "callback_username_check";
    $rules['password']    = "required";        
    $this->validation->set_rules($rules);
        
    if ($this->validation->run() == FALSE)
    {
        $this->load->view('myform');
    }
    else
    {
        // success, write to the database!
    }

Problem is, I want to show a preview / confirmation page before writing to the database. In the bad old days before frameworks, I'd just create a confirmation page with a form and a bunch of hidden fields. User would confirm, then I'd validate the data write to the DB. Is there an easier way to do this with CodeIgniter?
#2

[eluser]abmcr[/eluser]
you can add a temp record in the table and set the default value to FALSE; after the preview, if you confimr, you set the field to TRUE...
#3

[eluser]Jesse Schutt[/eluser]
thbt,

Did you have any luck with this? I'd be curious to see how you made this work.

Thanks Much!

Jesse
#4

[eluser]TheFuzzy0ne[/eluser]
Is there any reason why you can't just insert the data into the database normally, and generate a preview from that? If it needs to be changed, you can extract the data from the database again to repopulate you form, and delete the database entries.
#5

[eluser]Jesse Schutt[/eluser]
So far I have the form validating the data and then passing it on to a view via a $data[] array. There is no database insertion yet. How can I allow the user to click an "Edit Details" button and have all that information loaded back into the form to be changed and revalidated?

Once it is correct, the user should be able to click "Continue" to make a payment.

[edit]Cross posting :-)[/edit]
#6

[eluser]Jesse Schutt[/eluser]
Thanks for the response!

I guess my question is more about what the normal way is to do something like this? If it is to make an insertion and then draw it out for the preview, then great! I don't know what the typical procedure looks like.

Jesse
#7

[eluser]TheFuzzy0ne[/eluser]
Oh I see. I can't comment on typical procedure, but only what makes sense to me.

The main issue I can see is with passing data between pages. Once it's been validated and passed, you shouldn't have to validate it again, which is why it makes sense to store it in the database. Obviously we could use flash data, but there's no guarantee the user is using cookies, although they will most likely be logged in.

I guess it depends on the purpose and the tools that are available, so I will go out on a limb and go as far as to say there is no "typical" way to do this. I believe it's purely circumstantial.

As for a solution to your previous post. I would go with some kind of table in your database to store temporary data, and a script that deletes any data older than a few hours or so. If it's secure data, wouldn't trust the user with it (although if the cookie is encrypted, they shouldn't be a problem), which means it should ideally never leave your server. Also, while the user may not be able to change your cookie as such, there's nothing stopping them deleting it, which may break your application.

Hope this helps, even though I know I haven't been able answer your original query.
#8

[eluser]Jesse Schutt[/eluser]
Quote:Hope this helps, even though I know I haven’t been able answer your original query.

Hey, just hearing other people's thoughts on this is very helpful!

I'll keep playing with this!

I appreciate the help

Jesse
#9

[eluser]xwero[/eluser]
Instead of a temp record you could make a temp table an place the fetched data there. Once the user confirms the data you can move it to the actual table and delete it from the temp table.
#10

[eluser]Jesse Schutt[/eluser]
xwero,

Thanks for the thoughts. What I am gathering about this is that there really isn't a *standard* way for this. I've read about hidden fields, session, temp db, etc. Right now I'm exploring the ci_session class...

Jesse




Theme © iAndrew 2016 - Forum software by © MyBB