/**
  * An ajax callback function that creates a new form with default fields and settings after checking the nonce.
  **/
 public function create_form_ajax()
 {
     $form_name = $_POST['form_name'];
     $post_type = $_POST['post_type'];
     $description = $_POST['form_description'];
     $parent_form_id = $_POST['parent_form'];
     $parent_form = false;
     $nonce = $_POST['_wpnonce'];
     if (!($form_name && $post_type)) {
         $response = array('success' => false, 'error' => __('You missed a required item.', 'wpfepp-plugin'));
         die(json_encode($response));
     }
     if (!wp_verify_nonce($nonce, 'wpfepp-create-form')) {
         $response = array('success' => false, 'error' => __('Security check failed!', 'wpfepp-plugin'));
         die(json_encode($response));
     }
     if ($parent_form_id != -1) {
         $parent_form = $this->db->get($parent_form_id);
         if ($parent_form && $parent_form['post_type'] != $post_type) {
             $response = array('success' => false, 'error' => __('You can only import items from a form which has the same post type as the one selected for this form.', 'wpfepp-plugin'));
             die(json_encode($response));
         }
     }
     $fields = $parent_form ? $parent_form['fields'] : $this->defaults['fields'][$post_type];
     $settings = $parent_form ? $parent_form['settings'] : $this->defaults['settings'];
     $emails = $parent_form ? $parent_form['emails'] : $this->defaults['emails'];
     $this->db->add($form_name, $post_type, $description, $fields, $settings, $emails);
     ob_start();
     $this->render_form_list_table();
     $table_html = ob_get_clean();
     $response = array('success' => true, 'table_html' => $table_html);
     die(json_encode($response));
 }