如何在表单操作之前运行php

时间:2016-11-06 19:02:40

标签: php html wordpress paypal html-form

我有一个运行php文件的表单,该文件将数据存储到wp数据库但是在运行php文件之后我需要将top函数作为paypal按钮。代码就是这样:

<form id="candle-form" action="<?php bloginfo('template_directory');?>/db-submit.php" method="post">

  ....form body (works properly)

</form>

基本上我需要运行action =&#34; https://www.paypal.com/cgi-bin/webscr"在php函数之后,用户可以用paypal结帐。有没有办法做到这一点?我尝试使用位置重定向:在php文件的末尾但是paypal链接只是转到paypal.com并且不保留表单的信息

1 个答案:

答案 0 :(得分:0)

对于您的表单提交,请提交到外部文件。

您可以在设置此代码之前运行任何操作。确保没有任何修改标题的内容。验证此代码有效。

{
// Prepare GET data
$query = array();
$query['cmd'] = '_xclick';

$query['business'] = ''; //Your email or account ID
$query['lc'] = 'US'; //Location
$query['item_name'] = ''; //Item Name
$query['button_subtype'] = 'services'; //Button type
$query['no_shipping'] = '0'; //Shipping?
$query['bn'] = 'PP-BuyNowBF:btn_buynow_LG.gif:NonHosted'; //Button type
$query['amount'] = ''; //amount
$query['return'] = ''; //Return url after purchase
$query['cancel_url'] = ''; //If user cancels payment, url to take them to

// Prepare query string
$query_string = http_build_query($query);

header('Location: https://www.sandbox.paypal.com/us/cgi-bin/webscr?' . $query_string);
}
相关问题