วิธีเปิดแบบฟอร์มการติดต่อ 7 โดยใช้ wordpress ajax

ฉันใช้ปลั๊กอิน contact จาก 7 และคำถามของฉันคือการเปิดแบบฟอร์มติดต่อ 7 ในป๊อปอัปผ่าน WordPress admin ajax แต่รหัสของฉันไม่ทำงาน เปิดเฉพาะป๊อปอัป แต่ไม่ได้ส่งแบบฟอร์มติดต่อ 7 กำลังเปลี่ยนเส้นทางใน URL ของผู้ดูแลระบบ ajax และส่งคืน 0

นี่คือโค้ดที่ฉันกำลังทำในfunctions.php

<?php
add_action('wp_head', 'my_action_popup_cf7_javascript');

function my_action_popup_cf7_javascript() {
?>
<script type="text/javascript" >
jQuery(document).ready(function($) {
    $('.myajaxcarrer').click(function(){
      //alert(1);
      var mydata = $(this).data();
      $(".overlay").fadeIn('slow');       
        var data = {
            action: 'my_action_popup_cf7',
            //whatever: 1234,
            id: mydata.id
        };
        // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
        //console.log(ajaxurl);
        $('.item').removeClass('active');
        $('[data-id=' + mydata.id + ']').parent().addClass('active');
        $.post('<?php echo esc_url( home_url() ); ?>/wp-admin/admin-ajax.php', data, function(response) {
           // alert('Got this from the server: ' + response);
           $('#testcarrer').html(response);
            var offset = $(window).scrollTop();

            $(".career-form").css("top", offset+50 );

            $('.closeBtn').click(function(e){
              e.preventDefault();
              $(".overlay").fadeOut('slow');
              $('.career-form').css("top", -1000+"%" )
            });
        });
    });
});

</script>
<?php
}

add_action('wp_ajax_my_action_popup_cf7', 'my_action_popup_cf7_callback');
add_action( 'wp_ajax_nopriv_my_action_popup_cf7', 'my_action_popup_cf7_callback' );

function my_action_popup_cf7_callback() {
     global $wpdb; // this is how you get access to the database
     //$whatever = 'ID=> '. $_POST['id'];
     //echo $whatever;
     ?>
     <a href="/th#" class="closeBtn">X</a>
      <h3>Apply Now</h3>
      <div class="formBox">
        <?php echo do_shortcode('[contact-form-7 id="905" title="My New Carrer Form"]'); ?>
      </div>
     <?php
     exit(); // this is required to return a proper result & exit is faster than die();
}

และโค้ดในไฟล์เทมเพลตเพจก็คือ

<span class="applyBtn"><a class="myajaxcarrer" data-id="903">Apply Now</a></span>

<div class="overlay"></div>
<div class="career-form">Ajax result Load here..</div>

และโค้ด js อยู่ด้านล่าง

$('.applyBtn').click(function(e){
  e.preventDefault();
  var offset = $(window).scrollTop();
  $(".overlay").fadeIn('slow'); 
  $(".career-form").css("top", offset+50 )
});

$('.closeBtn, .overlay').click(function(e){
  e.preventDefault();
  $(".overlay").fadeOut('slow');
  $('.career-form').css("top", -1000+"%" )
});

person Shashank Sharma    schedule 10.11.2016    source แหล่งที่มา


คำตอบ (1)


คุณสามารถเปิดได้โดย echoing do_shortcode('[form name with id]'); มันอยู่ในฟังก์ชัน php ของคุณ

person MOHD TAHIR    schedule 16.12.2016