PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.9.1
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.9.1
2.13.0 2.13.1 2.12.0 2.11.1 2.11.0 2.10.0 2.9.0 2.7.4 2.7.5 2.7.6 2.7.7 2.8.0 2.8.1 2.9.1 trunk 1.0 1.0-beta1 1.0-beta2 1.0-beta3 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 All 80 releases
ablocks / includes / blocks / form-builder / actions / save-form-data.php

save-form-data.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.9.1, at includes/blocks/form-builder/actions/save-form-data.php

90 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocks\Blocks\FormBuilder\Actions;
3
4 use ABlocks\Blocks\FormBuilder\Actions\Interfaces\FormSubmissionAction;
5 use ABlocks\Blocks\FormBuilder\ValidateFormData;
6 use ABlocks\Blocks\FormBuilder\Query;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11 /**
12 * Save Form data to db
13 */
14 final class SaveFormData implements FormSubmissionAction {
15
16 /** @var $validateformdata */
17 private ValidateFormData $validateformdata;
18
19 /**
20 * Contructor
21 *
22 * @param ValidateFormData $obj
23 */
24 public function __construct( ValidateFormData $obj ) {
25 $this->validateformdata = $obj;
26 }
27
28 public function action() {
29 if (
30 $this->validateformdata->form_info['info']['type'] === 'contact' &&
31 ! in_array( 'submission', $this->validateformdata->form_info['info']['actions'], true )
32 ) {
33 return;
34 }
35
36 // detemine this request coming from subscription form & email is not exists
37 if (
38 $this->validateformdata->form_info['info']['type'] === 'subscription' &&
39 Query::is_email_exists( $this->validateformdata->form_info['info']['email'], 'subscription' )
40 ) {
41 $this->validateformdata->set_error_message( __( 'Already subscribed.', 'ablocks' ) );
42 $this->validateformdata->state_data['dont_send_subs_email'] = true;
43 return;
44 }
45
46 /**
47 * By default both userIp, userAgent are in submissionMetaData, but here it is not available, an empty array.
48 * when a single element is selected, the single element became available
49 * but when both are selected it is not available
50 */
51 $settings = $this->validateformdata->form_info['info']['config']['submissionMetaData'] ?? [];
52
53 $ip = '';
54 if ( in_array( 'userIp', $settings, true ) ) {
55 $ip = sanitize_text_field(
56 $_SERVER['HTTP_CF_CONNECTING_IP'] ??
57 $_SERVER['HTTP_CLIENT_IP'] ??
58 $_SERVER['HTTP_X_FORWARDED_FOR'] ??
59 $_SERVER['REMOTE_ADDR'] ?? ''
60 );
61 }
62
63 $user_agents = '';
64 if ( in_array( 'userAgent', $settings, true ) ) {
65 $user_agents = sanitize_text_field(
66 $_SERVER['HTTP_USER_AGENT'] ?? ''
67 );
68 }
69
70 // insert data to entry
71 $id = Query::add_new_entry(
72 $this->validateformdata->form_info['info']['type'],
73 $this->validateformdata->form_info['info']['postId'],
74 $this->validateformdata->form_info['info']['email'],
75 $ip,
76 $user_agents,
77 $this->validateformdata->form_info['data'],
78 $this->validateformdata->form_info['info']['config']['block_id'],
79 boolval( $this->validateformdata->form_info['info']['config']['emailVerification'] ?? false )
80 );
81
82 if ( $id ) {
83 $this->validateformdata->state_data['submission_id'] = $id;
84 $this->validateformdata->set_message( __( 'Success!', 'ablocks' ) );
85 return;
86 }
87 $this->validateformdata->set_error_message( __( 'Failed to save data', 'ablocks' ) );
88 }
89 }
90