我需要通过点击提交按钮提交具有特定值的表单。单击“提交”按钮时,我希望将其重定向到要求捐赠的PayPal。提交捐赠后,我需要将客户重定向到我的网站,其中提交了包含值的表单并向客户显示。但是现在我被困住了。如果我在支付或取消捐赠后按下提交按钮,则在我的主要表单中输入的值与标题和网站没有任何关系。 我的代码看起来像这样:
<form action="adding.php" method="post" enctype='multipart/form-data'>
<table>
<tr>
<td class="abc">
<p id="insert">Title:*</p><br>
<input type="text" name="title" class="abcd" value="<?php echo $title; ?>" />
</td>
<td class="abc">
<p id="insert">Website:*</p><br>
<input type="text" name="website" class="abcd" value="<?php echo $website; ?>" />
</td>
</tr>
</table>
<input type="submit" value="Submit" id="submit" name="submit" />
</form>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="EJJ5RT9MEEJSC">
<input type="image" src="http://localhost/www/images/submit.png" id="submit" name="submit" border="0" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
<?php
$sql2 = "INSERT INTO `www` (title, website)
VALUES ('$title', '$website')";
?>
<?php
if (isset($_POST['submit'])) {
$con = mysql_connect("localhost","root","");
if (!$con){
exit("Can not connect: " . mysql_error());
}
mysql_select_db("www",$con);
?>
<?php
if ((strlen($title) < 3) or (strlen($title) > 15)) {
echo "<h1 id='top'>Title must be between 3 and 15 characters long!</h1>";
} else if (filter_var($website, FILTER_VALIDATE_URL) === false) {
echo("<h1 id='top'>Website: Please enter a valid website to your wish.</h1>");
}
else
{
mysql_query($sql2,$con);
mysql_close($con);
header("Location:index.php");
}
?>
答案 0 :(得分:0)
首先在adding.php中添加数据库相关代码,其中第一个表单提交值,并以此形式(adding.php),使用javascript提交paypal捐赠表单
即在页面卸载时调用javascript函数:call_paypal。
function call_paypal(){document.getElementById(&#34; paypal_frm&#34;)。submit();}
&LT; form action =&#34; https://www.paypal.com/cgi-bin/webscr" ID =&#34; paypal_frm&#34;方法=&#34;后&#34;目标=&#34; _top&#34; &GT;
&LT; / form&gt;
已经完成......