PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 1.1.8
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v1.1.8
3.3.1 V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 2.10.1 All 138 releases
bit-form / includes / Frontend / Ajax / FrontendAjax.php

FrontendAjax.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 1.1.8, at includes/Frontend/Ajax/FrontendAjax.php

111 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 BitCode\BitForm\Frontend\Ajax;
4
5 use BitCode\BitForm\Core\Util\HttpHelper;
6 use BitCode\BitForm\Core\Form\FormHandler;
7 use BitCode\BitForm\Frontend\Form\FrontendFormManager;
8 use BitCode\BitForm\Core\Integration\IntegrationHandler;
9 use BitCode\BitForm\Core\Form\Validator\FormFieldValidator;
10
11 class FrontendAjax
12 {
13 public function register()
14 {
15 add_action('wp_ajax_nopriv_bitforms_submit_form', array($this, 'submit_form'));
16 add_action('wp_ajax_bitforms_submit_form', array($this, 'submit_form'));
17 }
18
19 public function submit_form()
20 {
21 \ignore_user_abort();
22 $form_id = str_replace('bitforms_', null, $_REQUEST['bitforms_id']);
23 $FrontendFormManager = new FrontendFormManager($form_id);
24 if (wp_verify_nonce($_REQUEST['bitforms_token'], $_REQUEST['bitforms_id'])) {
25 unset($_REQUEST['_ajax_nonce']);
26 unset($_REQUEST['action']);
27 if ($FrontendFormManager->isExist()) {
28 $isRestricted = $FrontendFormManager->checkSubmissionRestriction();
29 if ($isRestricted && !empty($isRestricted)) {
30 wp_send_json_error($isRestricted[0]);
31 }
32 $captchaSettings = $FrontendFormManager->getCaptchaSettings();
33 if ($captchaSettings) {
34 $token = $_REQUEST['g-recaptcha-response'];
35 if (!isset($_REQUEST['g-recaptcha-response'])) {
36 wp_send_json_error(
37 __(
38 'Please verify reCAPTCHA',
39 'bitform'
40 )
41 );
42 }
43 $integrationHandler = new IntegrationHandler(0);
44 $allFormIntegrations = $integrationHandler->getAllIntegration('app', 'gReCaptcha');
45 if (!is_wp_error($allFormIntegrations)) {
46 foreach ($allFormIntegrations as $integration) {
47 if (!is_null($integration->integration_type) && $integration->integration_type === 'gReCaptcha') {
48 $integrationDetails = json_decode($integration->integration_details);
49 $integrationDetails->id = $integration->id;
50 $reCAPTCHA = $integrationDetails;
51 }
52 }
53 }
54 if (!empty($reCAPTCHA->secretKey)) {
55 $gRecaptchaResponse = HttpHelper::post(
56 'https://www.google.com/recaptcha/api/siteverify',
57 ['secret' => $reCAPTCHA->secretKey, 'response' => $token]
58 );
59 $isgReCaptchaVerified = false;
60 if (!is_wp_error($gRecaptchaResponse)) {
61 $gRecaptchaResponse = $gRecaptchaResponse->success;
62 }
63 if (!$gRecaptchaResponse) {
64 wp_send_json_error(
65 __(
66 'Please verify reCAPTCHA',
67 'bitform'
68 )
69 );
70 }
71 }
72 }
73 unset($_REQUEST['g-recaptcha-response']);
74 $validatedFormData = $FrontendFormManager->validateFormSubmission($_REQUEST);
75 $form_fields = $FrontendFormManager->getFields();
76 $formFieldValidator = new FormFieldValidator($form_fields, $validatedFormData, $_FILES);
77 $validateField = $formFieldValidator->validate('create', $form_id);
78 if ($validateField) {
79 $saveResponse = $FrontendFormManager->saveFormEntry($validatedFormData);
80 $FrontendFormManager->setSubmissionCount();
81 $responseMsg = is_array($saveResponse) && !empty($saveResponse) ? $saveResponse : __('Form Submitted Successfully', 'bitform');
82 wp_send_json_success($responseMsg);
83 } else {
84 // if (!$validateForm) {
85 // $errorMessages = __('Please submit form with valid fields', 'bitform');
86 // } else {
87 $errorMessages = count($formFieldValidator->getMessage()) > 0 ?
88 $formFieldValidator->getMessage() : null;
89 // }
90 wp_send_json_error($errorMessages, 400);
91 }
92 }
93 wp_send_json_error(
94 __(
95 'Form does not exist',
96 'bitform'
97 ),
98 400
99 );
100 } else {
101 wp_send_json_error(
102 __(
103 'Token expired',
104 'bitform'
105 ),
106 401
107 );
108 }
109 }
110 }
111