PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 5.2.0
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v5.2.0
6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 3.6.66 All 195 releases
fluentform / app / Http / Controllers / FormController.php

FormController.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 5.2.0, at app/Http/Controllers/FormController.php

175 lines 4.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentForm\App\Http\Controllers;
4
5 use Exception;
6 use FluentForm\App\Services\Form\FormService;
7
8 class FormController extends Controller
9 {
10 /**
11 * Get the paginated forms matching search criteria.
12 *
13 * @param \FluentForm\App\Services\Form\FormService $formService
14 * @return \WP_REST_Response
15 */
16 public function index(FormService $formService)
17 {
18 return $this->sendSuccess(
19 $formService->get($this->request->all())
20 );
21 }
22
23 /**
24 * Create a form from backend/editor
25 *
26 * @param \FluentForm\App\Services\Form\FormService $formService
27 * @return \WP_REST_Response
28 */
29 public function store(FormService $formService)
30 {
31 try {
32 $form = $formService->store($this->request->all());
33
34 return $this->sendSuccess([
35 'formId' => $form->id,
36 'redirect_url' => admin_url(
37 'admin.php?page=fluent_forms&form_id=' . $form->id . '&route=editor'
38 ),
39 'message' => __('Successfully created a form.', 'fluentform'),
40 ]);
41 } catch (Exception $e) {
42 return $this->sendError([
43 'message' => $e->getMessage(),
44 ], 422);
45 }
46 }
47
48 public function duplicate(FormService $formService)
49 {
50 try {
51 $form = $formService->duplicate($this->request->all());
52
53 return $this->sendSuccess([
54 'message' => __('Form has been successfully duplicated.', 'fluentform'),
55 'form_id' => $form->id,
56 'redirect' => admin_url('admin.php?page=fluent_forms&route=editor&form_id=' . $form->id),
57 ], 200);
58 } catch (Exception $e) {
59 return $this->sendError([
60 'message' => $e->getMessage(),
61 ], 422);
62 }
63 }
64
65 public function find(FormService $formService)
66 {
67 try {
68 $id = $this->request->get('form_id');
69
70 $form = $formService->find($id);
71
72 return $this->sendSuccess($form, 200);
73 } catch (Exception $e) {
74 return $this->sendError([
75 'message' => $e->getMessage(),
76 ], 422);
77 }
78 }
79
80 public function delete(FormService $formService)
81 {
82 try {
83 $id = $this->request->get('form_id');
84
85 $formService->delete($id);
86
87 return $this->sendSuccess([
88 'message' => __('Successfully deleted the form.', 'fluentform'),
89 ], 200);
90 } catch (Exception $e) {
91 return $this->sendError([
92 'message' => $e->getMessage(),
93 ], 422);
94 }
95 }
96
97 public function update(FormService $formService)
98 {
99 try {
100 $formService->update($this->request->all());
101
102 return $this->sendSuccess([
103 'message' => __('The form is successfully updated.', 'fluentform'),
104 ], 200);
105 } catch (Exception $e) {
106 return $this->sendError([
107 'message' => $e->getMessage(),
108 ], 422);
109 }
110 }
111
112 public function convert(FormService $formService)
113 {
114 try {
115 $formService->convert($this->request->get('form_id'));
116
117 return $this->sendSuccess([
118 'message' => __('The form is successfully converted.', 'fluentform'),
119 ], 200);
120 } catch (Exception $e) {
121 return $this->sendError([
122 'message' => $e->getMessage(),
123 ], 422);
124 }
125 }
126
127 public function templates(FormService $formService)
128 {
129 try {
130 return $this->sendSuccess($formService->templates(), 200);
131 } catch (Exception $e) {
132 return $this->sendError([
133 'message' => $e->getMessage(),
134 ], 422);
135 }
136 }
137
138 public function resources(FormService $formService, $formId)
139 {
140 $components = $formService->components($formId);
141
142 $disabledComponents = $formService->getDisabledComponents();
143
144 return $this->sendSuccess([
145 'components' => $components,
146 'disabled_components' => $disabledComponents,
147 'shortcodes' => fluentFormEditorShortCodes(),
148 ]);
149 }
150
151 public function fields(FormService $formService, $formId)
152 {
153 return $this->sendSuccess($formService->fields($formId));
154 }
155
156 public function shortcodes(FormService $formService, $formId)
157 {
158 return $this->sendSuccess($formService->shortcodes($formId));
159 }
160
161 public function pages(FormService $formService)
162 {
163 return $this->sendSuccess($formService->pages());
164 }
165 public function findShortCodePage(FormService $formService, $formId)
166 {
167 return $this->sendSuccess($formService->findShortCodePage($formId));
168 }
169
170 public function ping()
171 {
172 return ['message' => 'pong'];
173 }
174 }
175