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