NF_AJAX_REST_Forms

The Ninja Forms NF AJAX REST Forms class.

Defined (1)

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

/includes/AJAX/REST/Forms.php  
  1. class NF_AJAX_REST_Forms extends NF_AJAX_REST_Controller 
  2. protected $action = 'nf_forms'; 
  3. private $forms_controller; 
  4. public function __construct() 
  5. parent::__construct(); 
  6. $this->forms_controller = new NF_Database_FormsController(); 
  7.  
  8. /** 
  9. * POST /forms/<id>/ 
  10. * @param array $request_data [ int $clone_id ] 
  11. * @return array $data [ int $new_form_id ] 
  12. */ 
  13. public function post( $request_data ) 
  14. if( isset( $request_data[ 'clone_id' ]) ) { 
  15. $clone_id = $request_data[ 'clone_id' ]; 
  16. $data[ 'new_form_id' ] = NF_Database_Models_Form::duplicate( $clone_id ); 
  17. return $data; 
  18.  
  19. /** 
  20. * GET forms/ 
  21. * @return array [ $forms ] 
  22. */ 
  23. public function get() 
  24. return $this->forms_controller->getFormsData(); 
  25.  
  26. /** 
  27. * DELETE forms/<id>/ 
  28. * @param array $request_data => [ form_id ] 
  29. * @return array $data => [ delete => null ] 
  30. */ 
  31. public function delete( $request_data ) 
  32. $id = $request_data[ 'form_id' ]; 
  33.  
  34. $form = Ninja_Forms()->form( $id )->get(); 
  35. $data[ 'delete' ] = $form->delete(); 
  36.  
  37. return $data; 
  38.  
  39. /** 
  40. * Form ID, Clone ID 
  41. * @return array $request_data 
  42. */ 
  43. protected function get_request_data() 
  44. $request_data = array(); 
  45.  
  46. /** 
  47. * FORM ID 
  48. */ 
  49. if( isset( $_REQUEST[ 'form_id' ] ) && $_REQUEST[ 'form_id' ] ) { 
  50. $request_data[ 'form_id' ] = absint( $_REQUEST[ 'form_id' ] ); 
  51.  
  52. /** 
  53. * CLONE ID 
  54. */ 
  55. if( isset( $_REQUEST[ 'clone_id' ] ) && $_REQUEST[ 'clone_id' ] ) { 
  56. $request_data[ 'clone_id' ] = absint( $_REQUEST[ 'clone_id' ] ); 
  57.  
  58. return $request_data;