Welcome Guest, Not a member yet? Register   Sign In
How to check if form was submitted in the view
#1

[eluser]landitus[/eluser]
I'm trying to do the following: I would like to have 1 view that is used for the form and the form validation and the form success as well. I'm using flashdata to inform the user about the process. But I would like to check wether or not the following code in the view is considered safe and good practice.

I placed this line:
Code:
$this->session->set_flashdata('exito', 'some message');
only to show when the form was saved to the database, so I should be covered right?

form_view.php
Code:
<!-- Flash Data -->
   <?php if ($this->session->flashdata('success')) {
       echo '<div class="msj success">'.$this->session->flashdata('success').'</div>';
   } elseif ($this->session->flashdata('error')) {
    echo '<div class="msj error">'.$this->session->flashdata('error').'</div>';
   } ?&gt;
  
  
   &lt;!-- if form was sent succesfull  --&gt;
   &lt;?php if($this->session->flashdata('success')) :?&gt;
  
    // Thank you message and some information about the next steps to follow...
  
   &lt;?php else :?&gt;
  
   &lt;!-- Render form --&gt;
         // Render form
                        &lt;?php endif :?&gt;
#2

[eluser]Aken[/eluser]
Unless you are redirecting after the form is processed, you don't need session data. Just pass a variable to your view like you would any other data, and give it a true or false value saying whether or not the form was processed successfully.




Theme © iAndrew 2016 - Forum software by © MyBB