【问题标题】:One form, one button, two actions - repost with code一个表单,一个按钮,两个动作 - 用代码重新发布
【发布时间】:2016-08-02 13:42:28
【问题描述】:

关于我今天早些时候提出的一个问题,我在下面发布了代码。

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

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

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

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

谢谢。

这是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>

【问题讨论】:

标签: php ajax forms action


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2016-12-07
    • 2012-05-19
    • 1970-01-01
    • 2013-01-14
    • 2018-01-13
    • 2015-07-04
    • 1970-01-01
    • 1970-01-01
    • 2017-01-31
    相关资源
    最近更新 更多