8

Anyone know why:

class Booking extends Controller {
 function booking()
 {
 parent::Controller();
 }
 function send_instant_to_paypal()
 {
 print_r($_POST);
 echo '<hr />';
 print_r($this->input->post());
 echo '<hr />';
 $id_booking = $this->input->post('id_booking');
 $title = $this->input->post('basket_description');
 $cost = ($this->input->post('fee_per_min') * $this->input->post('amount'));
 echo $id_booking;
 echo $title
 echo $cost
 }
}

Will echo post variables in CI for $_POST but NOT for $this->input->post();?

I've got $this->input->post() in use and working on a search page elsewhere in the site... but on this page, it's not working.. here's my form...

<form id="add_funds" action="' . site_url('booking/send_instant_to_paypal') . '" method="post">
<input type="text" name="amount" id="amount" value="" />
<input type="hidden" name="id_booking" id="id_booking" value="0" />
<input type="hidden" name="basket_description" id="basket_description" value="Adding Credit" />
<input type="hidden" name="fee_per_min" id="fee_per_min" value="' . $fee_per_min . '" />
<input type="submit" value="Add to basket" />
</form>

It's mental ;-p Anyone spot anything obviously stupid I'm missing?

Cœur
39k25 gold badges207 silver badges282 bronze badges
asked Mar 23, 2011 at 17:52
1
  • CI2.1 or CI1.X? Looks like CI1, which means your call to $this->input-post() is wrong Commented Mar 23, 2011 at 17:56

3 Answers 3

7

You most likely have XSS or CSRF enabled and it will prohibit (guessing here) Paypal to get those details back to you.

This is typical of CodeIgniter, and there are some work arounds like excluding CSRF for certain controllers (via config or hook).

If you give some more details on where the POST is coming from I can answer a bit clearly.

edit

could be that you are calling $this->input->post() incorrectly? I know that CI2.1 added support for $this->input->post() to return the full array, but until this point you had to explicitly define the post variable you wanted ala:

$user = $this->input->post('username');

answered Mar 23, 2011 at 17:54
Sign up to request clarification or add additional context in comments.

3 Comments

To be honest, paypal is not in the loop yet (it will be). All I'm doing is loading the form in a view and posting to the controller/method supplied above. Nothing else is going on.. I've broken it down to the basics too.. :-(
I suspect you are confusing the CI2.1 documentation (userguide) with a CI1.X release, so $this->input->post() will not return an array for you. Look here in latest change log: codeigniter.com/user_guide/changelog.html
Indeed, that was a rookie mistake.. However, I was adding explicit post variables, to which I've added to my first post. These variables are NOT echoing... I can't fathom why...
2

I resolved the issue with excluding CSRF protection for that particular method

you can add this code in application/config/config.php

if(stripos($_SERVER["REQUEST_URI"],'/Booking/send_instant_to_paypal') === FALSE)
{
 $config['csrf_protection'] = TRUE;
}
else
{
 $config['csrf_protection'] = FALSE;
}
answered May 28, 2013 at 8:42

Comments

0

The only thing I can think of right now is that you maybe did not load the form helper, but I'm not sure if it's being used for that. you can do this in the /config/autoload.php

I for example have this:

$autoload['helper'] = array('url', 'form', 'html', 'site_helper', 'upload_helper');

you can also load it in your function itself as follow:

function send_instant_to_paypal()
 {
 $this->load->helper('form');
 print_r($_POST);
 echo '<hr />';
 print_r($this->input->post());
 echo '<hr />';
 $id_booking = $this->input->post('id_booking');
 $title = $this->input->post('basket_description');
 $cost = ($this->input->post('fee_per_min') * $this->input->post('amount'));
 echo $id_booking;
 echo $title
 echo $cost
 }
answered Mar 24, 2011 at 10:37

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.