NF_AJAX_Controllers_FormEndpoints

The Ninja Forms NF AJAX Controllers FormEndpoints class.

Defined (1)

The class is defined in the following location(s).

/includes/AJAX/Controllers/FormEndpoints.php  
  1. class NF_AJAX_Controllers_FormEndpoints extends NF_Abstracts_Controller 
  2. /** 
  3. * Constructor 
  4. */ 
  5. public function __construct() 
  6. // add_action( 'wp_ajax_nf_get_forms', array( $this, 'get_forms' ) ); 
  7. // add_action( 'wp_ajax_nf_get_new_form_templates', array( $this, 'get_new_form_templates' ) ); 
  8. // add_action( 'wp_ajax_nf_delete', array( $this, 'delete' ) ); 
  9. // add_action( 'wp_ajax_nf_duplicate', array( $this, 'duplicate' ) ); 
  10.  
  11. /** 
  12. */ 
  13. public function get_forms() 
  14. $db_forms_controller = new NF_Database_FormsController(); 
  15. $forms_json = $db_forms_controller->getFormsData(); 
  16. $this->_respond( $forms_json ); 
  17.  
  18. /** 
  19. */ 
  20. public function get_new_form_templates() 
  21. $templates = Ninja_Forms()->config( 'NewFormTemplates' ); 
  22. die( json_encode( $templates ) ); 
  23.  
  24. /** 
  25. */ 
  26. public function delete() 
  27. $id = $_REQUEST[ 'form_id' ]; 
  28.  
  29. try{ 
  30. $form = Ninja_Forms()->form( $id )->get(); 
  31. $this->_data[ 'delete' ] = $form->delete();; 
  32. } catch( Exception $e ) { 
  33. $this->_data[ 'errors' ][] = $e->getMessage(); 
  34. $this->_respond(); 
  35.  
  36. public function duplicate() 
  37. $form_id = $_REQUEST[ 'form_id' ]; 
  38.  
  39. //Copied and pasted from NF_Database_models_Form::duplicate line 136 
  40. $form = Ninja_Forms()->form( $form_id )->get(); 
  41.  
  42. $settings = $form->get_settings(); 
  43.  
  44. $new_form = Ninja_Forms()->form()->get(); 
  45. $new_form->update_settings( $settings ); 
  46.  
  47. $form_title = $form->get_setting( 'title' ); 
  48.  
  49. $new_form_title = $form_title . " - " . __( 'copy', 'ninja-forms' ); 
  50.  
  51. $new_form->update_setting( 'title', $new_form_title ); 
  52.  
  53. $new_form->update_setting( 'lock', 0 ); 
  54.  
  55. $new_form->save(); 
  56.  
  57. $new_form_id = $new_form->get_id(); 
  58.  
  59. $fields = Ninja_Forms()->form( $form_id )->get_fields(); 
  60.  
  61. foreach( $fields as $field ) { 
  62.  
  63. $field_settings = $field->get_settings(); 
  64.  
  65. $field_settings[ 'parent_id' ] = $new_form_id; 
  66.  
  67. $new_field = Ninja_Forms()->form( $new_form_id )->field()->get(); 
  68. $new_field->update_settings( $field_settings )->save(); 
  69.  
  70. $actions = Ninja_Forms()->form( $form_id )->get_actions(); 
  71.  
  72. foreach( $actions as $action ) { 
  73.  
  74. $action_settings = $action->get_settings(); 
  75.  
  76. $new_action = Ninja_Forms()->form( $new_form_id )->action()->get(); 
  77. $new_action->update_settings( $action_settings )->save(); 
  78.  
  79. return $new_form_id; 
  80.