开发者

Codeigniter paypal_lib->ammount from form?

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', 'admin_1261513315_biz@pixelcraftw开发者_JAVA技巧ebdesign.com');
    $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?!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜