Welcome Guest, Not a member yet? Register   Sign In
Form flow

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
function insert()
            echo 'do something with the data, like sending to a model function';
            $this->load->helper(array('form', 'url'));
            //get data to populate the form with select options
            $data['countries'] = $this->mdTest->get_all_countries();        
I came to this because I don´t want to create a new function only to receive the data from the form.


[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') {

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
<form action="http://localhost/oliver/convenios/sucesso" method="post" id="formConvenio">

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

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

And after test the presence of an $_POST? can i access the $_POST directly?

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

Theme © iAndrew 2016 - Forum software by © MyBB