CodeIgniter Forums
How to check if form was submitted in the view - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How to check if form was submitted in the view (/showthread.php?tid=48603)



How to check if form was submitted in the view - El Forum - 01-22-2012

[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;



How to check if form was submitted in the view - El Forum - 01-23-2012

[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.