dongtu4028 2018-10-10 23:13
浏览 160

在Wordpress中使用AJAX提交的注册表单

I am having some headaches solving this issue. I have a Wordpress / Woocommerce Signup Form which fires a couple of actions in order to work. In addition to those actions I want to post the form data to a CRM. It is working fine independently but not together.

Here is the Form Markup:

<form id="bc_post-register" method="post" class="register">

  <?php do_action( 'woocommerce_action_one' ); ?>

  <input placeholder="E-Mail*" type="email" class="woocommerce-Input woocommerce-Input--text input-text" name="email" id="reg_email" value="<?php if ( ! empty( $_POST['email'] ) ) echo esc_attr( $_POST['email'] ); ?>" />
  <input type="submit" class="woocommerce-Button button" name="register" value="Kostenlos einschreiben" />

</form>

 <?php do_action( 'woocommerce_action_two' );?> 
 <?php do_action( 'woocommerce_action_three' );?>

Here is my AJAX:

jQuery(document).ready(function(event) {
   jQuery('#bc_post-register').submit(ajaxSubmit);
   function ajaxSubmit() {
   var ConvForm = jQuery(this).serialize();

jQuery.ajax({
  type:    "POST",
  url:     "https://app.crm.com/directory/id/action",
  data:    ConvForm,
  success: function(data) {
     console.log("has been sent");
  }
});
return false; 
} 
});

It's all working beautifully but not together. How can I bring the puzzle together and fire the Actions and my AJAX?

  • 写回答

1条回答 默认 最新

  • duangao8359 2018-10-11 00:25
    关注

    I made some subtle changes. Also, make sure that you have jQuery installed.

    Try this and see if it helps:

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    
    <script>
    
    $(document).ready(function(event){ 
    
      $('#bc_post-register').submit(function(event){
    
        event.preventDefault(); //Prevents your from submitting/refreshing.
        var string = $('#bc_post-register').serialize();
    
          $.ajax({
              type: "POST",
              url: "https://app.crm.com/directory/id/action.php", //added the .php
              data: string,
              dataType: 'json', //The response needs to be a json formatted string.
              cache: false,
              success: function(response){
    
                console.log('This is your response: ' + response);
    
              }else{
    
                console.log('There was a problem submitting your ajax.');  
    
                }
          });
    
      });
    
    });
    
    </script>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题