PluginProbe ʕ •ᴥ•ʔ
PiWeb Product Enquiry or product catalog for WooCommerce / 2.2.33.21
PiWeb Product Enquiry or product catalog for WooCommerce v2.2.33.21
2.2.34.43 2.2.34.42 2.2.34.41 2.2.34.40 2.2.34.39 trunk 2.2.22 2.2.26 2.2.33.16 2.2.33.17 2.2.33.19 2.2.33.20 2.2.33.21 2.2.33.22 2.2.33.23 2.2.33.24 2.2.33.26 2.2.33.27 2.2.33.29 2.2.33.30 2.2.33.31 2.2.33.32 2.2.33.33 2.2.33.34 2.2.33.36 2.2.33.37 2.2.33.39 2.2.33.40 2.2.33.41 2.2.33.42 2.2.33.43 2.2.33.44 2.2.33.46 2.2.33.47 2.2.33.49 2.2.34.0 2.2.34.1 2.2.34.10 2.2.34.11 2.2.34.12 2.2.34.13 2.2.34.14 2.2.34.16 2.2.34.17 2.2.34.19 2.2.34.2 2.2.34.20 2.2.34.21 2.2.34.22 2.2.34.23 2.2.34.24 2.2.34.26 2.2.34.27 2.2.34.29 2.2.34.3 2.2.34.30 2.2.34.31 2.2.34.32 2.2.34.33 2.2.34.34 2.2.34.36 2.2.34.37 2.2.34.4 2.2.34.6 2.2.34.7 2.2.34.9
enquiry-quotation-for-woocommerce / public / class-pisol-form.php
enquiry-quotation-for-woocommerce / public Last commit date
css 2 years ago img 2 years ago js 2 years ago partials 2 years ago class-email.php 2 years ago class-eqw-advance.php 2 years ago class-eqw-enquiry-cart.php 2 years ago class-eqw-enquiry-shortcode.php 2 years ago class-eqw-product.php 2 years ago class-eqw-save-enquiry.php 2 years ago class-pisol-enquiry-quotation-woocommerce-public.php 2 years ago class-pisol-form.php 2 years ago class-webhook.php 2 years ago index.php 2 years ago
class-pisol-form.php
192 lines
1 <?php
2
3 class class_pisol_form{
4
5 public $items;
6 public $template;
7 public $errors;
8
9 function __construct($items){
10 $this->items = $items;
11 $this->template = 'template1';
12 $this->errors = array();
13 if($this->enquiryPresent()){
14 $this->form_page();
15 }
16 }
17
18 function enquiryPresent(){
19 return true; //(class_eqw_enquiry_cart::isThereProductsInEnquirySession());
20 }
21
22 function form_page(){
23 if(!empty($_POST) && count($_POST) > 0 ){
24 $this->validation();
25 $this->error();
26 if($this->submit_form()){
27 $this->success_msg();
28 }else{
29 $this->form();
30 }
31
32 }else{
33 $this->form();
34 }
35 }
36
37 function form(){
38 echo '<form method="post" id="pi-eqw-enquiry-form">';
39 $this->items();
40 echo '</form>';
41 }
42
43 function success_msg(){
44 echo '<div class="woocommerce-notices-wrapper">';
45 echo '<div class="woocommerce-message"><span id="pi-form-submitted-success"></span>';
46 echo __('Enquiry submitted','pisol-enquiry-quotation-woocommerce');
47 echo '</div>';
48 echo '</div>';
49 }
50
51 function validation(){
52 foreach($this->items as $item){
53 $this->required($item);
54 }
55 }
56
57 function required($item){
58 if(isset($item['required']) && $item['required'] == 'required'){
59 if(isset($_POST[$item['name']]) && $_POST[$item['name']] != ""){
60 return true;
61 }else{
62 $this->errors[] = array(
63 'error'=> sprintf(__('Cant leave %s empty','pisol-enquiry-quotation-woocommerce'), $item['placeholder'])
64 );
65 }
66 }
67 return true;
68 }
69
70 function submit_form(){
71 if( count($this->errors) <= 0 && !empty($_POST)){
72 $save = $this->saveEnquiry();
73 if($save !== false){
74 $email = $this->sendEmail($save);
75 $clear_product = $this->clearSession();
76 return true;
77 }
78 }
79 return false;
80 }
81
82 function saveEnquiry(){
83 $obj = new class_eqw_save_enquiry($this->items);
84 return $obj->save();
85 }
86
87 function sendEmail($enq_id){
88 $email_obj = new class_pisol_eqw_email($this->items, $enq_id);
89 $email_obj->sendEmail();
90 return true;
91 }
92
93 function clearSession(){
94 class_eqw_enquiry_cart::deleteProductsFromEnquirySession();
95 return true;
96 }
97
98 function error(){
99 $error_msg = "";
100 if(is_array($this->errors) && count($this->errors) > 0){
101 foreach($this->errors as $error){
102 $error_msg .= $error['error'].'<br>';
103 }
104 }
105
106 if($error_msg != ""){
107 echo '<div class="woocommerce-notices-wrapper">';
108 echo '<div class="woocommerce-message">';
109 echo $error_msg;
110 echo '</div>';
111 echo '</div>';
112 }
113 }
114
115 function items(){
116 foreach($this->items as $item){
117 $this->item($item);
118 }
119 }
120
121 function item($item){
122 if(method_exists($this,$item['type'])){
123 $this->{$item['type']}($item);
124 }
125 }
126
127 function errorMsgLabel($item){
128 $error_label = '';
129 if($item['name'] === 'pi_phone'){
130 $error_label .= ' data-msg-digits="'.esc_attr__('Please enter only digits.','pisol-enquiry-quotation-woocommerce').'" ';
131 }
132
133 if(isset($item['required']) && $item['required'] === 'required'){
134 $error_label .= ' data-msg-required="'.esc_attr__('This field is required.','pisol-enquiry-quotation-woocommerce').'" ';
135 }
136
137 if($item['name'] === 'pi_email'){
138 $error_label .= ' data-msg-email="'.esc_attr__('Please enter a valid email address','pisol-enquiry-quotation-woocommerce').'" ';
139 }
140
141 return $error_label;
142 }
143
144 function text($item){
145
146 if($item['name'] === 'pi_phone'){
147 $rule = ' data-rule-digits ';
148 }
149
150 $error_label = $this->errorMsgLabel($item);
151
152 $field = '<input type="text" name="'.$item['name'].'" '.($item['required'] == 'required' ? 'required' : '').' placeholder="'.$item['placeholder'].'" class="%s" '.(isset($rule) ? $rule : '').' '.$error_label.'/>';
153
154 $this->{$this->template}($field, $item);
155 }
156
157 function email($item){
158 $error_label = $this->errorMsgLabel($item);
159
160 $field = '<input type="email" name="'.$item['name'].'" '.($item['required'] == 'required' ? 'required' : '').' placeholder="'.$item['placeholder'].'" class="%s" '.$error_label.'/>';
161
162 $this->{$this->template}($field, $item);
163 }
164
165 function submit($item){
166 $field = '<input type="submit" value="'.$item['value'].'" class="%s" />';
167
168 $this->{$this->template}($field, $item);
169 }
170
171 function textarea($item){
172 $error_label = $this->errorMsgLabel($item);
173
174 $field = '<textarea name="'.$item['name'].'" '.($item['required'] == 'required' ? 'required' : '').' placeholder="'.$item['placeholder'].'" class="%s" '.$error_label.'></textarea>';
175
176 $this->{$this->template}($field, $item);
177 }
178
179 function template1($field, $item){
180 $class_name = isset($item['type']) ? "type-".$item['type'] : "no-type";
181 $id = isset($item['name']) ? 'field-container-'.$item['name'] : "";
182 echo '<div class="pi-row '.esc_attr($class_name).'" id="'.esc_attr($id).'">';
183 echo '<div class="pi-col-12">';
184 if($item['type'] == 'submit'){
185 printf($field, 'pi-btn pi-btn-primary pi-submit-enq-button');
186 }else{
187 printf($field, 'pi-form-control');
188 }
189 echo '</div>';
190 echo '</div>';
191 }
192 }