tags:

views:

69

answers:

1

I need to get the quantity of items from a form and pass that to CI's paypal_lib auto_form:

This is my controller:

function auto_form()
{
 $this->paypal_lib->add_field('business', '[email protected]');
    $this->paypal_lib->add_field('return', site_url('home/success'));
    $this->paypal_lib->add_field('cancel_return', site_url('home/cancel'));
    $this->paypal_lib->add_field('notify_url', site_url('home/ipn')); // <-- IPN url
    $this->paypal_lib->add_field('custom', '1234567890'); // <-- Verify return

    $this->paypal_lib->add_field('item_name', 'Paypal Test Transaction');
    $this->paypal_lib->add_field('item_number', '001');
    $this->paypal_lib->add_field('quantity', $quant);
    $this->paypal_lib->add_field('amount', '1');

    $this->paypal_lib->paypal_auto_form();
}

I have a library of my own that validates the input and redirects to auto_form on validation. I just need to pass the var $quant to the controller.

How can I achieve this?!

+1  A: 

If you're redirecting directly to the auto_form controller method you can setup an argument there to pass your data in:

auto_form($quant)

Then, depending assuming you have no routes, rewriting, or querystrings 'on' (basically a stock CI setup) to interfere, and you are using the URL helper to redirect, you would do your redirect something like this:

redirect('/index.php/your_controller/auto_form/'. $quantity_from_form);

More on passing URI segments to your functions here.


Or if you're already using CI sessions in your application you can add the quantity value to a session variable for later retrieval inside of the auto_form controller method:

// Set After Your Form Passed Validation
$this->session->set_userdata('quant', $quantity_from_form);

// Retrieve Later in Controller Method After Redirect
$this->paypal_lib->add_field('quantity', $this->session->userdata('item'));

More on CI sessions here.

Trae
Is there any reason not to use session data? (generally speaking)
Kevin Brown
That's just great! Thanks, Trae.Do you have a preference? Is one safer than the other? Faster? Smarter? I'm a noob!
Kevin Brown
The sessions solution is likely easiest to implement as the data is simply available once invoked, as opposed to the URL argument setup relying on you passing the data around yourself.
Trae