如何向两个方向发送行动表格?

时间:2017-01-15 11:02:23

标签: php html

我有代码发送到邮件,我没有破坏这段代码。 我不知道页面动作收到表单信息..我不会将代码发送到两个方向,在这样的同时。

<from action ="firstdiraction.php" action="seconddirction.php" >

2 个答案:

答案 0 :(得分:0)

使用jQuery和AJAX:

<form id="my_form" action="javascript:sendForm()">
  Form...
</form>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script type="text/javascript">
  function sendForm() {
    var form = $('#my_form');
    $.ajax({
      type: "POST",
      url: 'firstdiraction.php',
      data: form.serialize(),
      success: function(response) {
        console.log(response);
      }
    });

    $.ajax({
      type: "POST",
      url: 'seconddirction.php',
      data: form.serialize(),
      success: function(response) {
        console.log(response);
      }
    });

  }
</script>

答案 1 :(得分:0)

好的,所以你想将表单数据发送到两个不同的php脚本,这可以通过ajax来完成:

    $(document).ready( function(){
    $('#SubmitButton').click(function(){
        //Send data to the email script
        $.post( 'firstdiraction.php', $('form').serialize(), function(data, textStatus) {
            //data is the result from the script
            alert(data);
        });

        //Send data to the other script
        $.post( 'seconddirction.php', $('form').serialize(), function(data, textStatus) {
            //data is the result from the script
            alert(data);
        });
    });
});

通过按表单标记<form> </form>

中的提交按钮,将触发上面的操作

jQuery aslo required,将其包含在您的页面上。