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

[eluser]JeremyApp[/eluser]
Someone correct me if this is a bad way to do it, but I generally use flashdata for this purpose.

Flashdata is a part of the CI session library that stores temporary variables, usually for the next request only (optionally the next two requests). I will usually write the inputted data to flashdata and then display it on the next page. Since it should be valid for another request, I can either choose to write it to the database or discard.

http://ellislab.com/codeigniter/user-gui...sions.html - see "Flashdata"
#12

[eluser]thbt[/eluser]
Here's how I ended up doing it.

Code:
if ( $this->form_validation->run() == FALSE || isset( $_POST['edit_listing'] ) )
{
    // show form
}
else
{
   // Data passed validation
   if ( !isset( $_POST["really_write_to_db"] ) )
   {
       // Show the preview
   }
   else
   {
       // write to DB
   }
}

So basically I have a preview page with a bunch of <INPUT TYPE="HIDDEN"...> tags to store the form data, plus a <INPUT TYPE="HIDDEN" NAME="really_write_to_db" VALUE=1> kind of thing to have the next submit really write to the database.

Nice thing about it is, the data gets validated every time it goes through this bit of code. Also, no need to write to the DB until the very end, which improves performance.

Hope this helps.
#13

[eluser]johnwbaxter[/eluser]
You really should be using the input class for dealing with post data so that it is sanitised and safe.

Code:
$this->input->post('edit_listing')
instead of
Code:
$_POST['edit_listing']
#14

[eluser]TheFuzzy0ne[/eluser]
[quote author="JeremyApp" date="1235083398"]Someone correct me if this is a bad way to do it, but I generally use flashdata for this purpose.

Flashdata is a part of the CI session library that stores temporary variables, usually for the next request only (optionally the next two requests). I will usually write the inputted data to flashdata and then display it on the next page. Since it should be valid for another request, I can either choose to write it to the database or discard.

http://ellislab.com/codeigniter/user-gui...sions.html - see "Flashdata"[/quote]

I wouldn't go as far as to say that that's the wrong way to do it, but I tend to see flashdata as being more of a convenience than anything else. I like to keep any data such as payment information away from the user. However, if the data is not of a sensitive nature, I love flashdata, but I only use flashdata in situations that I know the user has cookies enabled. For example, when they are logged in. If they are logged in then they have cookies enabled, if they're not, we can't be sure, so assuming they do might break your application.
#15

[eluser]thbt[/eluser]
[quote author="audiopleb" date="1235083951"]You really should be using the input class for dealing with post data so that it is sanitised and safe.

Code:
$this->input->post('edit_listing')
instead of
Code:
$_POST['edit_listing']
[/quote]

I probably should. In CI 1.7, is there no way to get all of the validated variables? With the old Validation class, I could do
Code:
$result = $this->validation;
but with the new Form Validation class, I don't think there's a way to do this, is there?




Theme © iAndrew 2016 - Forum software by © MyBB