使用一个提交按钮对表单提交执行两项操作

时间:2020-05-16 14:12:11

标签: php html

我的网站上有一个html表单,以便用户可以订阅我的邮件列表。我正在使用getResponse建立我的列表并发送自动电子邮件。为此,我将“ https://app.getresponse.com/add_subscriber.html”放入表单的action属性中。这是我表单的简化版本:

<form action="https://app.getresponse.com/add_subscriber.html" method="post">
    <input type="text" name="name" id="name" class="required">
    <input type="email" name="email" id="email">
    <input type="submit" name="submitBtn" value=“Subscribe”>
</form> 

我还有一个send.php文件,可将用户信息插入服务器上的MySQL数据库。但是,由于我只能在action属性中指定一个文件,因此,当用户单击“订阅”时,我不知道必须同时执行getResponse脚本和我自己的脚本。

基本上,我想实现以下行为:当某人单击“订阅”时,他们的信息应发送到getResponse并发送到我的邮件列表中,并发送到我服务器上的MySQL DB中。

我花了数小时在网上寻找信息,但没有找到任何可行的方法。 预先谢谢你。

1 个答案:

答案 0 :(得分:0)

给您的表格一个ID,说main_game_function ()

myForm

然后拦截表单的Submit事件并阻止将其提交到app.getresponse.com,而是调用ajax到您的<form action="https://app.getresponse.com/add_subscriber.html" method="post" id="myForm"> ,以传递表单数据,一旦send.php返回,则将表单提交给app.getresponse。 com

send.php