forked from gabcarvalhogama/elementic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Elementic_Form_Action.php
105 lines (73 loc) · 3.01 KB
/
Elementic_Form_Action.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
class Elementic_Form_Action extends \ElementorPro\Modules\Forms\Classes\Action_Base {
public function get_name() {return 'Mautic';}
public function get_label() {return __( 'Mautic', 'text-domain' );}
/**
* register elementor forms
* @param type $widget
* @return type
*/
public function register_settings_section( $widget ) {
$widget->start_controls_section(
'section_mautic',
[
'label' => __( 'Mautic', 'text-domain' ),
'condition' => [
'submit_actions' => $this->get_name(),
],
]
);
$widget->add_control(
'mautic_url',
[
'label' => __( 'Mautic Form URL *', 'text-domain' ),
'type' => \Elementor\Controls_Manager::URL,
'placeholder' => 'http://yourmauticurl.com/',
'label_block' => true,
'separator' => 'before',
'description' => __( 'Enter the URL where you have Mautic installed', 'text-domain' ),
]
);
$widget->add_control(
'mautic_form_id',
[
'label' => __('Mautic Form ID *', 'text-domain'),
'type' => \Elementor\Controls_Manager::TEXT,
'placeholder' => '99',
'label_block' => true,
'separator' => 'before',
'description' => __( 'Fill with your form id', 'text-domain' ),
]
);
$widget->end_controls_section();
}
public function run( $record, $ajax_handler ) {
$settings = $record->get( 'form_settings' );
// Make sure that there is a Mautic url
if ( empty( $settings['mautic_url'] ) ) {
return;
}
// Make sure that there have a Form ID
if ( empty( $settings['mautic_form_id'] ) ) {
return;
}
// Get sumitetd Form data
$raw_fields = $record->get( 'fields' );
// Normalize the Form Data
$fields = [
'formId' => $settings['mautic_form_id']
];
foreach ( $raw_fields as $id => $field ) {
$fields[ $id ] = $field['value'];
}
$response = wp_remote_post(rtrim($settings['mautic_url']['url'],"/")."/form/submit?formId=".$settings['mautic_form_id'], [
'body' => ["mauticform" => $fields],
'headers' => [ 'X-Forwarded-For' => $_SERVER[ "REMOTE_ADDR" ]]
] );
// $message = preg_match('/<div class=\"well text-center\">(.*?)<\/div>/s', $response['body'], $match);
// echo trim(strip_tags($match[1]));
}
public function on_export( $element ) {
return $element;
}
}