Skip to content

Instantly share code, notes, and snippets.

@aimahdi
Created June 5, 2025 07:59
Show Gist options
  • Save aimahdi/6b760fa278da31ca0bb4b435f32d5286 to your computer and use it in GitHub Desktop.
Save aimahdi/6b760fa278da31ca0bb4b435f32d5286 to your computer and use it in GitHub Desktop.
add_action('fluentform/loaded', function ($app) {
$app->router->post('/submit-form', function () use ($app) {
try {
$data = $app->request->get('data');
$data['_wp_http_referer'] = isset($data['_wp_http_referer']) ? sanitize_url(urldecode($data['_wp_http_referer'])) : '';
$app->request->merge(['data' => $data]);
$formId = intval($app->request->get('form_id'));
$response = (new FluentForm\App\Services\Form\SubmissionHandlerService())->handleSubmission($data, $formId);
return $app->response->json($response);
} catch (FluentForm\Framework\Validator\ValidationException $e) {
return $app->response->json($e->errors(), $e->getCode());
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment