简体   繁体   English

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

[英]How to run php before form action

I have a form that runs a php file that stores data to a wp database however after it runs the php file I need to top function as a paypal button. 我有一个运行可将数据存储到wp数据库的php文件的表单,但是在运行php文件后,我需要首先将其用作贝宝按钮。 The code is this at the moment: 现在的代码是这样的:

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

  ....form body (works properly)

</form>

basically I need to run action="https://www.paypal.com/cgi-bin/webscr" after the php function so that the user can checkout with paypal. 基本上,我需要在php函数之后运行action =“ https://www.paypal.com/cgi-bin/webscr”,以便用户可以使用paypal进行结帐。 Is there any way to do this? 有什么办法吗? I tried redirecting with Location: at the end of the php file but then the paypal link just goes to paypal.com and doesn't retain the form's info 我尝试使用Location:重定向到php文件的末尾,但随后paypal链接仅转到paypal.com,并且不保留表单的信息

For your form submission, submit to an external file. 要提交表单,请提交到外部文件。

You can run any operations before this code is set. 您可以在设置此代码之前运行任何操作。 Make sure there isn't anything modifying the headers. 确保没有任何修改标头。 This code is verified to be working. 该代码已验证为有效。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM