0

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

3
  • can you print the whole post array using this echo "<pre>";print_r($_POST); Commented Apr 17, 2013 at 6:01
  • Thanks Venkat, returns an empty array. but as mentioned, using the post values in a new array, $data and passing that to view works fine. so just not available to controller.
    – Smudger
    Commented Apr 17, 2013 at 6:06
  • can you post the your $data array here Commented Apr 17, 2013 at 6:14

2 Answers 2

1

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.

2
  • Thanks Camron. Any advice/reading on how to use a hidden variable to do this?
    – Smudger
    Commented Apr 17, 2013 at 6:07
  • 1
    A hidden variable can be used (in javascript) the same way as a regular input. The value just needs to be changed with the javascript. At which point it can be used as a regular form input on submit. You (if using form_helper) must pass the hidden inputs into form_open. After which you should be able to change the value in the javascript.
    – Camron
    Commented Apr 17, 2013 at 6:18
0
<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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.