dpjpo746884 2017-03-14 19:47
浏览 75

onClick获取表单详细信息并发送电子邮件

I have a form with after closing form tag an a link. I want to get the form input and have send them to my e-mail when clicking the link. When clicked the user should stay on the same page but hiding the form. This is my (simplified) markup:

<script type="text/javascript">
  function doSomething() {
   $.get("sendform.php");
   return false;
  }
</script>

<form id="myForm">
  First name:<br>
  <input type="text" name"first name"><br>
  Last name:<br>
  <input type="text" name="lastname">
</form>
<a href="#" onClick="doSomething();">Send</a>

Can I use the $.post() method? And if I can, how would I do this?

  • 写回答

3条回答 默认 最新

  • dongxiatuo9827 2017-03-14 19:52
    关注
    1. Get form data.
    2. Prepare ajax post(url,sendData,callback).
    3. Hide form.
    4. (Optional) Do some action after successful submit.
      function doSomething() {
          var form = $('#myForm');
          var formdata = form.serialize();// 1
          $.post("sendform.php",formdata, function(data){ //2
              //here you can do different action after make you post request //4
          });
          form.hide(); //3
      }
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
      <form id="myForm">
        First name:<br>
        <input type="text" name="first_name"><br>
        Last name:<br>
        <input type="text" name="lastname">
      </form>
      <a href="#" onClick="doSomething();">Send</a>




    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答