CodeIgniter Forums
Form flow - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Form flow (/thread-20849.html)



Form flow - El Forum - 07-23-2009

[eluser]OllieBR[/eluser]
Hi guys, i´m new to CI my question is that if is right to make (whitout form validation class) a form using the same function that send you the view with the form as the function that receives the $_POST, something like this
Code:
function insert()
    {            
        if($_POST){
            echo 'do something with the data, like sending to a model function';
        }else{
            $this->load->helper(array('form', 'url'));
            
            //get data to populate the form with select options
            $data['countries'] = $this->mdTest->get_all_countries();        
            
            $this->load->view('Test/viewInsert',$data);
        }
    }
I came to this because I don´t want to create a new function only to receive the data from the form.

tnx


Form flow - El Forum - 07-23-2009

[eluser]louis w[/eluser]
Sure you can do that, but I wouldn't use _POST

I would do something like:

if ($this->input->post('form_action') == 'update') {


Form flow - El Forum - 07-23-2009

[eluser]OllieBR[/eluser]
Hummm nice! i look for this in the user guide and found the Input and security class, tanks!
But tell me the 'form_action' and update are defaults values on CI? or are attributes of the html form tag?

it will work for this form action
Code:
<form action="http://localhost/oliver/convenios/sucesso" method="post" id="formConvenio">



Form flow - El Forum - 07-23-2009

[eluser]louis w[/eluser]
No, this would be a value posted from your form. Either a button or hidden input element.


Form flow - El Forum - 07-23-2009

[eluser]Colin Williams[/eluser]
I just see if the post array is empty, or if you're considering using the Form_validation class, these are the three conditions you respond to

Form validation fail + no errors = not yet submitted.
Form validation fail + errors = form submitted, but errors encountered.
Form validation passes = form submitted and succeeded.


Form flow - El Forum - 08-10-2009

[eluser]OllieBR[/eluser]
And after test the presence of an $_POST? can i access the $_POST directly?


Form flow - El Forum - 08-10-2009

[eluser]Chad Fulton[/eluser]
I don't want to confuse matters, but I thought that I would point this out to prevent you from having an irrational fear of using the $_POST array.

There is no reason to not use the $_POST array directly.

The only time it makes sense to use $this->input->post('key') is if you are planning to use CodeIgniter's XSS (cross site scripting) cleaning, in which case you would to $this->input->post('key', true).

Using $this->input->post('key') does not help you in any way, and causes unnecessary function calls, which increases overhead.