Smudger
Smudger

Reputation: 10791

codeigniter post value not available to form. use post value in controller logic

I have some syntax in my controller:

  $data = array(
   'submit' =>$this->input->post('submit'),
   'period' =>$this->input->post('period'),
   'buom' =>$this->input->post('buom'),
   'creditlimit' => $this->sales_model->get_creditlimit($this->input->post('customer'))
  );

This works perfect when I pass it to my view, all the array elements become variables as intended.

what I want to do though is use $this->input->post('submit') in an if statement but $this->input->post('submit') does not output to the controller itself, only the view.

if I simply do the following:

echo $this->input->post('submit');

PHP returns no value even thought the post is being displayed normally by the view?

how can I make this post value available to my controller and perform logic against it.

my overall objective is that my submitting form has three different submit buttons. Depending on the submit button they click I would like to load a different view for each submit.

so something like:

if($this->input->post('submit')==="option1")
{$this->load->view('view1');}
else
{$this->load->view('view2');}

Am I do something stupid?

Thanks in advance as always, Regards...

Upvotes: 0

Views: 209

Answers (2)

Smudger
Smudger

Reputation: 10791

<SCRIPT>
function submitFunction(i) {
   if (i==1) document.theForm.action=
      "http://www.company.com/cgi-bin/cgi1.cgi";
   if (i==2) document.theForm.action=
      "http://www.company.com/cgi-bin/cgi2.cgi";
   if (i==3) document.theForm.action=
      "http://www.company.com/cgi-bin/cgi3.cgi";
   document.theForm.submit()
   }
</SCRIPT>

<FORM NAME="theForm">
<INPUT TYPE="button" VALUE="Submit 1" onClick="submitFunction(1)">
<INPUT TYPE="button" VALUE="Submit 2" onClick="submitFunction(2)">
<INPUT TYPE="button" VALUE="Submit 3" onClick="submitFunction(3)">
</FORM>

Upvotes: 0

Camron
Camron

Reputation: 308

Don't use the submit, if you have 3 different values for submit, you have javascript running on the page. It would be better to use a hidden variable. CodeIgniter has it's limitations, this is one where you're going to have to manipulate the form helper (at least as far as I know). I apologize if there is a way around this that I don't know; but, in my experience, this is not something that can/should be used with the PHP POST array.

Upvotes: 1

Related Questions