一个表单,一个按钮,两个动作-用代码转发


One form, one button, two actions - repost with code

继我今天早些时候提出的一个问题之后,我发布了下面的代码。

问题是我如何在一个窗体/一个按钮上完成两个操作。有些人推荐AJAX,我也做了一些研究,但解决方案对我来说并不清楚

目前,用户单击orderbelow.php上的按钮,然后向网站所有者发送一封电子邮件(send-order.php),然后将用户发送到completeyourorder.php。在这里,他们单击表单上的按钮将其发送到贝宝。

我想删除这个额外的步骤,这样当他们点击orderbelow.php时,电子邮件就会发送给所有者,用户就会被发送到贝宝(请记住,两个信息会被发送到如下所示的贝宝网页,即服务和价格)。

我是一个相对缺乏经验的程序员。我可以看到这里已经有类似的问题了,但到目前为止还无法确定在我的特定情况下我需要做什么。

谢谢。

这是orderbelow.php 的表单代码

<p>
<b>Personalised <?php echo $_GET['service']; ?></b>
<b>Price: &pound;<?php echo $_GET['p'];?></b>
</p>

<form name="orderform" action="send-order.php" onsubmit="return validateForm()" method="post">
<p>Name<br /><input name="clientname" value="<?echo $clientname;?>" type="text" style="width: 350px;" /></p>
<p>Email<br /><input name="email" value="<?echo $email;?>" type="text" style="width: 350px;" /></p>
<p>Date of Birth <i>(dd/mm/yyyy)</i><br /><input name="dateofbirth" value="<?echo $dateofbirth;?>" type="text" style="width: 350px;" /></p>
<p>Please tell me any questions you want covered in your session<br /><textarea name="questions" style="width: 500px; height: 200px;"><?echo str_replace("<br />","'r'n",$questions);?></textarea></p>
<p>Please tell me the first name of anyone you are asking about and describe any other relevant details you wish to share<br /><textarea name="comments" style="width: 500px; height: 200px;"><?echo str_replace("<br />","'r'n",$comments);?></textarea></p>

<p><br /><input type="hidden" name="service" value="<?
echo $_GET['service'];
?>" />
<input type="hidden" name="p" value="<?
echo $_GET['p'];
?>"
 />
<input type="submit" value="Order now" /></p>
 </form>

这是completeyourorder.php的表单代码。它发送两条数据来填充Paypal结账,即服务"服务"和价格"p"。

<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post"><p><input type="image" src="images/addtobasket.gif" name="submit" alt="Make payments with PayPal - fast, free and secure!" /><img alt="" src="https://www.paypal.com/en_GB/i/scr/pixel.gif" width="1" height="1" /><input type="hidden" name="add" value="1" /><input type="hidden" name="cmd" value="_cart" /><input type="hidden" name="business" value="xxxx@xxxxxx.co.uk" /><input type="hidden" name="item_name" value="<?php
echo $_GET['service'];
?>" /><input type="hidden" name="amount" value="<?php
echo $_GET['p'];
?>" /><input type="hidden" name="no_note" value="1" /><input type="hidden" name="currency_code" value="GBP" /><input type="hidden"  name="bn" value="PP-ShopCartBF" /></p></form>

尝试使用AJAX调用onSubmit。以下伪代码(带有一些jquery):

$("#form_name").submit(function() {
  $.ajax:
  method: post
  action: php_email_function_url
  success: function() {
  redirect to new page
  };
)};