| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentForm\App\Http\Controllers; |
| 4 |
|
| 5 |
use FluentForm\App\Services\Form\SubmissionHandlerService; |
| 6 |
use FluentForm\Framework\Validator\ValidationException; |
| 7 |
|
| 8 |
class SubmissionHandlerController extends Controller |
| 9 |
|
| 10 |
{ |
| 11 |
/** |
| 12 |
* Handle form submission |
| 13 |
*/ |
| 14 |
public function submit() |
| 15 |
{ |
| 16 |
try { |
| 17 |
parse_str($this->request->get('data'), $data); // Parse the url encoded data from the request object. |
| 18 |
$data['_wp_http_referer'] = isset($data['_wp_http_referer']) ? sanitize_url(urldecode($data['_wp_http_referer'])) : ''; |
| 19 |
$this->request->merge(['data' => $data]); // Merge it back again to the request object. |
| 20 |
|
| 21 |
$formId = intval($this->request->get('form_id')); |
| 22 |
$response = (new SubmissionHandlerService())->handleSubmission($data, $formId); |
| 23 |
|
| 24 |
return $this->json($response); |
| 25 |
} catch (ValidationException $e) { |
| 26 |
|
| 27 |
return $this->json($e->errors(), $e->getCode()); |
| 28 |
} |
| 29 |
} |
| 30 |
} |
| 31 |
|