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


How to run php before form action

我有一个形式,运行一个php文件,存储数据到一个wp数据库,但之后它运行的php文件,我需要作为一个贝宝按钮的顶级功能。现在的代码是:

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

基本上我需要在php函数之后运行action="https://www.paypal.com/cgi-bin/webscr",以便用户可以与paypal结帐。有什么办法可以做到吗?我尝试重定向与位置:在php文件的末尾,但paypal链接只是到paypal.com,不保留表单的信息

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

您可以在设置此代码之前运行任何操作。确保没有任何东西修改标题。此代码已被验证可以工作。

{
// 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);
}