Load gravity form using AJAX

We can load gravity form using simple AJAX loading dynamically.

PHP Ajax hook for wordpress

// Hook up the AJAX ajctions
add_action( 'wp_ajax_nopriv_gf_button_get_form', 'gf_button_ajax_get_form' );
add_action( 'wp_ajax_gf_button_get_form', 'gf_button_ajax_get_form' );

function gf_button_ajax_get_form(){
	$form_id = isset( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : 0;
	$section_icon_id = $_GET['section_icon_id'];
	echo '<div id="law_types_form"><div class="law_types_form"><span data-section_close_icon_id="'.$section_icon_id.'" class="close_form"><i aria-hidden="true" class="fa fa-close"></i></span> ';
	gravity_form( $form_id,false, false, false, false, true );
	echo '</div></div>';
	die();
}

Javascript code for calling AJAX

<script type="text/javascript">
  jQuery( document ).ready(function() {
      jQuery(document).on('click', '.law_following_area ul li.email_popup', function(){
        var section_icon_id = jQuery(this).data('section_icon_id');
        var section_id = 'section-' + section_icon_id;
          jQuery.get('<?php echo $ajax_url; ?>?action=gf_button_get_form&form_id=<?php echo $form_id; ?>&section_icon_id='+section_icon_id,function(response){
            jQuery("#"+section_id).append(response);
            jQuery("#"+section_id).addClass('add_popup_form');
            //button.remove();
            if(window['gformInitDatepicker']) {gformInitDatepicker();}
          });

      });
      jQuery(document).on('click', '.practice_areas_wrap .close_form', function(){
          var section_close_icon_id = jQuery(this).data('section_close_icon_id');
          jQuery('#section-'+section_close_icon_id+ ' #law_types_form').remove();
          jQuery('#section-'+section_close_icon_id).removeClass('add_popup_form');
      });
  });
</script>