| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentForm\App\Services\Migrator\Classes; |
| 4 |
|
| 5 |
use FluentForm\App\Modules\Form\FormFieldsParser; |
| 6 |
use FluentForm\App\Services\Submission\SubmissionService; |
| 7 |
use FluentForm\Framework\Helpers\ArrayHelper; |
| 8 |
|
| 9 |
abstract class BaseMigrator |
| 10 |
{ |
| 11 |
/** Constants used for default entry migrations max limit */ |
| 12 |
const DEFAULT_ENTRY_MIGRATION_MAX_LIMIT = 1000; |
| 13 |
public $key; |
| 14 |
public $title; |
| 15 |
public $shortcode; |
| 16 |
public $submitBtn; |
| 17 |
public $unSupportFields = []; |
| 18 |
|
| 19 |
|
| 20 |
public function import_forms($selectedForms = []) |
| 21 |
{ |
| 22 |
if (!$this->exist()) { |
| 23 |
wp_send_json_error([ |
| 24 |
'message' => sprintf( |
| 25 |
/* translators: %s Target Plugin Name */ |
| 26 |
__('%s is not installed.', 'fluentform'), |
| 27 |
$this->title), |
| 28 |
]); |
| 29 |
} |
| 30 |
|
| 31 |
$failed = []; |
| 32 |
|
| 33 |
$forms = $this->getForms(); |
| 34 |
|
| 35 |
if (!$forms) { |
| 36 |
wp_send_json_error([ |
| 37 |
'message' => __('No forms found!', 'fluentform'), |
| 38 |
]); |
| 39 |
} |
| 40 |
$insertedForms = []; |
| 41 |
$refs = get_option('__ff_imorted_forms_map'); |
| 42 |
$refs = is_array($refs) ? $refs : []; |
| 43 |
if ($forms && is_array($forms)) { |
| 44 |
|
| 45 |
foreach ($forms as $formItem) { |
| 46 |
$formId = $this->getFormId($formItem); |
| 47 |
if (!empty($selectedForms) && !in_array($formId, $selectedForms)) { |
| 48 |
continue; |
| 49 |
} |
| 50 |
|
| 51 |
$formFields = $this->getFields($formItem); |
| 52 |
if ($formFields) { |
| 53 |
$formFields = json_encode($formFields); |
| 54 |
} else { |
| 55 |
$failed[] = $this->getFormName($formItem); |
| 56 |
continue; |
| 57 |
} |
| 58 |
$form = [ |
| 59 |
'title' => $this->getFormName($formItem), |
| 60 |
'form_fields' => $formFields, |
| 61 |
'status' => 'published', |
| 62 |
'has_payment' => 0, |
| 63 |
'type' => 'form', |
| 64 |
'created_by' => get_current_user_id(), |
| 65 |
'conditions' => '', |
| 66 |
'appearance_settings' => '' |
| 67 |
]; |
| 68 |
|
| 69 |
if ($formId = $this->isAlreadyImported($formItem)) { |
| 70 |
$insertedForms = $this->updateForm($formId, $formFields, $insertedForms); |
| 71 |
} else { |
| 72 |
list($insertedForms, $formId) = $this->insertForm($form, $insertedForms, $formItem); |
| 73 |
} |
| 74 |
//get metas |
| 75 |
$metas = $this->getFormMetas($formItem); |
| 76 |
$this->updateMetas($metas, $formId); |
| 77 |
|
| 78 |
|
| 79 |
$refs[$formId] = [ |
| 80 |
'imported_form_id' => $this->getFormId($formItem), |
| 81 |
'form_type' => $this->key, |
| 82 |
]; |
| 83 |
|
| 84 |
} |
| 85 |
$msg = ''; |
| 86 |
if (count($failed) > 0) { |
| 87 |
$msg = "These forms was not imported for invalid data : " . implode(', ', $failed); |
| 88 |
} |
| 89 |
if (count($insertedForms) > 0) { |
| 90 |
update_option('__ff_imorted_forms_map', $refs, 'no'); |
| 91 |
wp_send_json([ |
| 92 |
'status' => true, |
| 93 |
'message' => "Your forms has been successfully imported. " . $msg, |
| 94 |
'inserted_forms' => array_values($insertedForms), |
| 95 |
'unsupported_fields' => array_values(array_unique(array_filter($this->unSupportFields))) |
| 96 |
], 200); |
| 97 |
return; |
| 98 |
} |
| 99 |
wp_send_json([ |
| 100 |
'message' => "No form is selected " . $msg, |
| 101 |
], 200); |
| 102 |
|
| 103 |
} |
| 104 |
|
| 105 |
wp_send_json([ |
| 106 |
'message' => __('Export error, please try again.', 'fluentform') |
| 107 |
], 422); |
| 108 |
} |
| 109 |
|
| 110 |
abstract protected function getForms(); |
| 111 |
|
| 112 |
abstract protected function getFields($form); |
| 113 |
|
| 114 |
abstract protected function getFormName($form); |
| 115 |
|
| 116 |
abstract protected function getFormMetas($form); |
| 117 |
|
| 118 |
abstract protected function getFormsFormatted(); |
| 119 |
|
| 120 |
abstract protected function exist(); |
| 121 |
|
| 122 |
public function getFluentClassicField($field, $args = []) |
| 123 |
{ |
| 124 |
if (!$field) { |
| 125 |
return; |
| 126 |
} |
| 127 |
$defaults = [ |
| 128 |
'index' => '', |
| 129 |
'uniqElKey' => '', |
| 130 |
'required' => false, |
| 131 |
'label' => '', |
| 132 |
'label_placement' => '', |
| 133 |
'admin_field_label' => '', |
| 134 |
'name' => '', |
| 135 |
'help_message' => '', |
| 136 |
'placeholder' => '', |
| 137 |
'fields' => [], |
| 138 |
'value' => '', |
| 139 |
'default' => '', |
| 140 |
'maxlength' => '', |
| 141 |
'options' => [], |
| 142 |
'class' => '', |
| 143 |
'format' => '', |
| 144 |
'validation_rules' => [], |
| 145 |
'conditional_logics' => [], |
| 146 |
'enable_image_input' => false, |
| 147 |
'calc_value_status' => false, |
| 148 |
'dynamic_default_value' => '', |
| 149 |
'container_class' => '', |
| 150 |
'id' => '', |
| 151 |
'number_step' => '', |
| 152 |
'step' => '1', |
| 153 |
'min' => '0', |
| 154 |
'max' => '10', |
| 155 |
'mask' => '', |
| 156 |
'temp_mask' => '', |
| 157 |
'enable_select_2' => 'no', |
| 158 |
'is_button_type' => '', |
| 159 |
'max_file_count' => '', |
| 160 |
'max_file_size' => '', |
| 161 |
'upload_btn_text' => '', |
| 162 |
'allowed_file_types' => '', |
| 163 |
'max_size_unit' => '', |
| 164 |
'html_codes' => '', |
| 165 |
'section_break_desc' => '', |
| 166 |
'tnc_html' => '', |
| 167 |
'prefix' => '', |
| 168 |
'suffix' => '', |
| 169 |
'layout_class' => '', |
| 170 |
'input_name_args' => '', |
| 171 |
'is_time_enabled' => '', |
| 172 |
'address_args' => '', |
| 173 |
'rows' => '', |
| 174 |
'cols' => '', |
| 175 |
'enable_calculation' => false, |
| 176 |
'calculation_formula' => '' |
| 177 |
]; |
| 178 |
|
| 179 |
$args = wp_parse_args($args, $defaults); |
| 180 |
return ArrayHelper::get(self::defaultFieldConfig($args), $field); |
| 181 |
} |
| 182 |
|
| 183 |
public static function defaultFieldConfig($args) |
| 184 |
{ |
| 185 |
$defaultElements = [ |
| 186 |
'input_name' => [ |
| 187 |
'index' => $args['index'], |
| 188 |
'element' => 'input_name', |
| 189 |
'attributes' => [ |
| 190 |
'name' => $args['name'], |
| 191 |
'data-type' => 'name-element' |
| 192 |
], |
| 193 |
'settings' => [ |
| 194 |
'container_class' => '', |
| 195 |
'admin_field_label' => 'Name', |
| 196 |
'conditional_logics' => [], |
| 197 |
'label_placement' => 'top' |
| 198 |
], |
| 199 |
'fields' => [ |
| 200 |
'first_name' => [ |
| 201 |
'element' => 'input_text', |
| 202 |
'attributes' => [ |
| 203 |
'type' => 'text', |
| 204 |
'name' => ArrayHelper::get($args, 'input_name_args.first_name.name'), |
| 205 |
'value' => ArrayHelper::get($args, 'input_name_args.first_name.default', ''), |
| 206 |
'id' => '', |
| 207 |
'class' => '', |
| 208 |
'placeholder' => ArrayHelper::get($args, 'input_name_args.first_name.placeholder' ,__('First Name', 'fluentform')), |
| 209 |
'maxlength' => '', |
| 210 |
], |
| 211 |
'settings' => [ |
| 212 |
'container_class' => '', |
| 213 |
'label' => ArrayHelper::get($args, 'input_name_args.first_name.label'), |
| 214 |
'help_message' => '', |
| 215 |
'visible' => ArrayHelper::isTrue($args, 'input_name_args.first_name.visible'), |
| 216 |
'validation_rules' => [ |
| 217 |
'required' => [ |
| 218 |
'value' => ArrayHelper::isTrue($args, 'input_name_args.first_name.required'), |
| 219 |
'message' => __('This field is required', 'fluentform'), |
| 220 |
], |
| 221 |
], |
| 222 |
'conditional_logics' => [], |
| 223 |
], |
| 224 |
'editor_options' => [ |
| 225 |
'template' => 'inputText' |
| 226 |
], |
| 227 |
], |
| 228 |
'middle_name' => [ |
| 229 |
'element' => 'input_text', |
| 230 |
'attributes' => [ |
| 231 |
'type' => 'text', |
| 232 |
'name' => ArrayHelper::get($args, 'input_name_args.middle_name.name'), |
| 233 |
'value' => ArrayHelper::get($args, 'input_name_args.middle_name.default', ''), |
| 234 |
'id' => '', |
| 235 |
'class' => '', |
| 236 |
'placeholder' => ArrayHelper::get($args, 'input_name_args.middle_name.placeholder' , __('Middle Name', 'fluentform')), |
| 237 |
'required' => false, |
| 238 |
'maxlength' => '', |
| 239 |
], |
| 240 |
'settings' => [ |
| 241 |
'container_class' => '', |
| 242 |
'label' => ArrayHelper::get($args, 'input_name_args.middle_name.label'), |
| 243 |
'help_message' => '', |
| 244 |
'error_message' => '', |
| 245 |
'visible' => ArrayHelper::isTrue($args, 'input_name_args.middle_name.visible'), |
| 246 |
'validation_rules' => [ |
| 247 |
'required' => [ |
| 248 |
'value' => ArrayHelper::isTrue($args, 'input_name_args.middle_name.required'), |
| 249 |
'message' => __('This field is required', 'fluentform'), |
| 250 |
], |
| 251 |
], |
| 252 |
'conditional_logics' => [], |
| 253 |
], |
| 254 |
'editor_options' => [ |
| 255 |
'template' => 'inputText' |
| 256 |
], |
| 257 |
], |
| 258 |
'last_name' => [ |
| 259 |
'element' => 'input_text', |
| 260 |
'attributes' => [ |
| 261 |
'type' => 'text', |
| 262 |
'name' => ArrayHelper::get($args, 'input_name_args.last_name.name'), |
| 263 |
'value' => ArrayHelper::get($args, 'input_name_args.last_name.default', ''), |
| 264 |
'id' => '', |
| 265 |
'class' => '', |
| 266 |
'placeholder' => ArrayHelper::get($args, 'input_name_args.last_name.placeholder', __('Last Name', 'fluentform')), |
| 267 |
'required' => false, |
| 268 |
'maxlength' => '', |
| 269 |
], |
| 270 |
'settings' => [ |
| 271 |
'container_class' => '', |
| 272 |
'label' => ArrayHelper::get($args, 'input_name_args.last_name.label'), |
| 273 |
'help_message' => '', |
| 274 |
'error_message' => '', |
| 275 |
'visible' => ArrayHelper::isTrue($args, 'input_name_args.last_name.visible'), |
| 276 |
'validation_rules' => [ |
| 277 |
'required' => [ |
| 278 |
'value' => ArrayHelper::isTrue($args, 'input_name_args.last_name.required'), |
| 279 |
'message' => __('This field is required', 'fluentform'), |
| 280 |
], |
| 281 |
], |
| 282 |
'conditional_logics' => [], |
| 283 |
], |
| 284 |
'editor_options' => [ |
| 285 |
'template' => 'inputText' |
| 286 |
], |
| 287 |
], |
| 288 |
], |
| 289 |
'editor_options' => [ |
| 290 |
'title' => 'Name Fields', |
| 291 |
'element' => 'name-fields', |
| 292 |
'icon_class' => 'ff-edit-name', |
| 293 |
'template' => 'nameFields' |
| 294 |
], |
| 295 |
], |
| 296 |
'input_text' => [ |
| 297 |
'index' => $args['index'], |
| 298 |
'element' => 'input_text', |
| 299 |
'attributes' => [ |
| 300 |
'type' => 'text', |
| 301 |
'name' => $args['name'], |
| 302 |
'value' => $args['value'], |
| 303 |
'class' => $args['class'], |
| 304 |
'id' => $args['id'], |
| 305 |
'placeholder' => $args['placeholder'], |
| 306 |
'maxlength' => $args['maxlength'], |
| 307 |
], |
| 308 |
'settings' => [ |
| 309 |
'container_class' => $args['container_class'], |
| 310 |
'label' => $args['label'], |
| 311 |
'label_placement' => $args['label_placement'], |
| 312 |
'admin_field_label' => $args['admin_field_label'], |
| 313 |
'help_message' => $args['help_message'], |
| 314 |
'conditional_logics' => [], |
| 315 |
'validation_rules' => [ |
| 316 |
'required' => [ |
| 317 |
'value' => $args['required'], |
| 318 |
'message' => 'This field is required' |
| 319 |
] |
| 320 |
], |
| 321 |
'is_unique' => 'no', |
| 322 |
'unique_validation_message' => 'This value need to be unique.' |
| 323 |
|
| 324 |
], |
| 325 |
'editor_options' => [ |
| 326 |
'title' => 'Simple Text', |
| 327 |
'icon_class' => 'ff-edit-text', |
| 328 |
'template' => 'inputText', |
| 329 |
], |
| 330 |
'uniqElKey' => $args['uniqElKey'], |
| 331 |
], |
| 332 |
'input_hidden' => [ |
| 333 |
'index' => $args['index'], |
| 334 |
'element' => 'input_hidden', |
| 335 |
'attributes' => [ |
| 336 |
'type' => 'hidden', |
| 337 |
'name' => $args['name'], |
| 338 |
'value' => $args['value'], |
| 339 |
], |
| 340 |
'settings' => [ |
| 341 |
'admin_field_label' => $args['admin_field_label'], |
| 342 |
], |
| 343 |
'editor_options' => [ |
| 344 |
'title' => __('Hidden Field', 'fluentform'), |
| 345 |
'icon_class' => 'ff-edit-hidden-field', |
| 346 |
'template' => 'inputHidden', |
| 347 |
], |
| 348 |
'uniqElKey' => $args['uniqElKey'], |
| 349 |
], |
| 350 |
'color_picker' => [ |
| 351 |
'index' => 15, |
| 352 |
'element' => 'color_picker', |
| 353 |
'attributes' => [ |
| 354 |
'type' => 'text', |
| 355 |
'name' => $args['name'], |
| 356 |
'value' => $args['value'], |
| 357 |
'class' => $args['class'], |
| 358 |
'id' => $args['id'], |
| 359 |
'placeholder' => $args['placeholder'], |
| 360 |
], |
| 361 |
'settings' => [ |
| 362 |
'container_class' => $args['container_class'], |
| 363 |
'label' => $args['label'], |
| 364 |
'label_placement' => $args['label_placement'], |
| 365 |
'admin_field_label' => $args['admin_field_label'], |
| 366 |
'help_message' => $args['help_message'], |
| 367 |
'conditional_logics' => [], |
| 368 |
'validation_rules' => [ |
| 369 |
'required' => [ |
| 370 |
'value' => $args['required'], |
| 371 |
'message' => 'This field is required' |
| 372 |
] |
| 373 |
], |
| 374 |
], |
| 375 |
'editor_options' => [ |
| 376 |
'title' => 'Color Picker', |
| 377 |
'icon_class' => 'ff-edit-tint', |
| 378 |
'template' => 'inputText' |
| 379 |
], |
| 380 |
'uniqElKey' => $args['uniqElKey'], |
| 381 |
], |
| 382 |
'input_url' => [ |
| 383 |
'index' => $args['index'], |
| 384 |
'element' => 'input_url', |
| 385 |
'attributes' => [ |
| 386 |
'type' => 'url', |
| 387 |
'name' => $args['name'], |
| 388 |
'value' => $args['value'], |
| 389 |
'class' => $args['class'], |
| 390 |
'id' => $args['id'], |
| 391 |
'placeholder' => $args['placeholder'], |
| 392 |
], |
| 393 |
'settings' => [ |
| 394 |
'container_class' => '', |
| 395 |
'label' => $args['label'], |
| 396 |
'label_placement' => $args['label_placement'], |
| 397 |
'admin_field_label' => $args['admin_field_label'], |
| 398 |
'help_message' => $args['help_message'], |
| 399 |
'validation_rules' => [ |
| 400 |
'required' => [ |
| 401 |
'value' => $args['required'], |
| 402 |
'message' => 'This field is required' |
| 403 |
], |
| 404 |
'url' => [ |
| 405 |
'value' => true, |
| 406 |
'message' => __('This field must contain a valid url', 'fluentform'), |
| 407 |
], |
| 408 |
], |
| 409 |
'conditional_logics' => [], |
| 410 |
|
| 411 |
], |
| 412 |
'editor_options' => [ |
| 413 |
'title' => __('Website URL', 'fluentform'), |
| 414 |
'icon_class' => 'ff-edit-website-url', |
| 415 |
'template' => 'inputText' |
| 416 |
], |
| 417 |
'uniqElKey' => $args['uniqElKey'], |
| 418 |
], |
| 419 |
'email' => [ |
| 420 |
'index' => $args['index'], |
| 421 |
'element' => 'input_email', |
| 422 |
'attributes' => [ |
| 423 |
'type' => 'email', |
| 424 |
'name' => $args['name'], |
| 425 |
'value' => $args['value'], |
| 426 |
'class' => $args['class'], |
| 427 |
'id' => '', |
| 428 |
'placeholder' => $args['placeholder'], |
| 429 |
], |
| 430 |
'settings' => [ |
| 431 |
'container_class' => '', |
| 432 |
'label' => $args['label'], |
| 433 |
'label_placement' => $args['label_placement'], |
| 434 |
'admin_field_label' => $args['admin_field_label'], |
| 435 |
'help_message' => $args['help_message'], |
| 436 |
'conditional_logics' => [], |
| 437 |
'validation_rules' => [ |
| 438 |
'required' => [ |
| 439 |
'value' => $args['required'], |
| 440 |
'message' => 'This field is required', |
| 441 |
], |
| 442 |
'email' => [ |
| 443 |
'value' => 1, |
| 444 |
'message' => 'This field must contain a valid email' |
| 445 |
] |
| 446 |
], |
| 447 |
'is_unique' => 'no', |
| 448 |
'unique_validation_message' => 'This value need to be unique.' |
| 449 |
|
| 450 |
], |
| 451 |
'editor_options' => [ |
| 452 |
'title' => 'Email Address', |
| 453 |
'icon_class' => 'ff-edit-email', |
| 454 |
'template' => 'inputText', |
| 455 |
], |
| 456 |
'uniqElKey' => $args['uniqElKey'], |
| 457 |
], |
| 458 |
'input_textarea' => [ |
| 459 |
'index' => $args['index'], |
| 460 |
'element' => 'textarea', |
| 461 |
'attributes' => [ |
| 462 |
'name' => $args['name'], |
| 463 |
'class' => $args['class'], |
| 464 |
'id' => '', |
| 465 |
'value' => $args['value'], |
| 466 |
'placeholder' => $args['placeholder'], |
| 467 |
'rows' => $args['rows'], |
| 468 |
'cols' => 2, |
| 469 |
'maxlength' => $args['maxlength'], |
| 470 |
], |
| 471 |
'settings' => [ |
| 472 |
'container_class' => '', |
| 473 |
'label' => $args['label'], |
| 474 |
'label_placement' => $args['label_placement'], |
| 475 |
'admin_field_label' => $args['admin_field_label'], |
| 476 |
'help_message' => $args['help_message'], |
| 477 |
'conditional_logics' => [], |
| 478 |
'validation_rules' => [ |
| 479 |
'required' => [ |
| 480 |
'value' => $args['required'], |
| 481 |
'message' => 'This field is required' |
| 482 |
], |
| 483 |
], |
| 484 |
], |
| 485 |
'editor_options' => [ |
| 486 |
'title' => 'Text Area', |
| 487 |
'icon_class' => 'ff-edit-textarea', |
| 488 |
'template' => 'inputTextarea', |
| 489 |
], |
| 490 |
'uniqElKey' => $args['uniqElKey'], |
| 491 |
], |
| 492 |
'select' => [ |
| 493 |
'index' => $args['index'], |
| 494 |
'element' => 'select', |
| 495 |
'attributes' => [ |
| 496 |
'name' => $args['name'], |
| 497 |
'value' => $args['value'], |
| 498 |
'class' => $args['class'], |
| 499 |
'id' => '', |
| 500 |
], |
| 501 |
'settings' => [ |
| 502 |
'container_class' => '', |
| 503 |
'label_placement' => $args['label_placement'], |
| 504 |
'admin_field_label' => $args['admin_field_label'], |
| 505 |
'label' => $args['label'], |
| 506 |
'help_message' => $args['help_message'], |
| 507 |
'placeholder' => $args['placeholder'], |
| 508 |
'advanced_options' => $args['options'], |
| 509 |
'calc_value_status' => $args['calc_value_status'], |
| 510 |
'enable_select_2' => $args['enable_select_2'], |
| 511 |
'enable_image_input' => false, |
| 512 |
'validation_rules' => [ |
| 513 |
'required' => [ |
| 514 |
'value' => $args['required'], |
| 515 |
'message' => 'This field is required' |
| 516 |
] |
| 517 |
], |
| 518 |
'randomize_options' => 'no', |
| 519 |
'conditional_logics' => [], |
| 520 |
], |
| 521 |
'editor_options' => [ |
| 522 |
'title' => 'Dropdown', |
| 523 |
'icon_class' => 'ff-edit-dropdown', |
| 524 |
'element' => 'select', |
| 525 |
'template' => 'select', |
| 526 |
], |
| 527 |
'uniqElKey' => $args['uniqElKey'], |
| 528 |
], |
| 529 |
'multi_select' => [ |
| 530 |
'index' => $args['index'], |
| 531 |
'element' => 'select', |
| 532 |
'attributes' => [ |
| 533 |
'name' => $args['name'], |
| 534 |
'value' => $args['value'], |
| 535 |
'id' => $args['id'], |
| 536 |
'class' => $args['class'], |
| 537 |
'placeholder' => $args['placeholder'], |
| 538 |
'multiple' => true, |
| 539 |
], |
| 540 |
'settings' => [ |
| 541 |
'dynamic_default_value' => $args['dynamic_default_value'], |
| 542 |
'help_message' => $args['help_message'], |
| 543 |
'container_class' => $args['container_class'], |
| 544 |
'label' => $args['label'], |
| 545 |
'admin_field_label' => $args['admin_field_label'], |
| 546 |
'label_placement' => $args['label_placement'], |
| 547 |
'placeholder' => $args['placeholder'], |
| 548 |
'max_selection' => '', |
| 549 |
'advanced_options' => $args['options'], |
| 550 |
'calc_value_status' => $args['calc_value_status'], |
| 551 |
'enable_image_input' => false, |
| 552 |
'validation_rules' => [ |
| 553 |
'required' => [ |
| 554 |
'value' => $args['required'], |
| 555 |
'message' => __('This field is required', 'fluentform'), |
| 556 |
], |
| 557 |
], |
| 558 |
'conditional_logics' => [], |
| 559 |
], |
| 560 |
'editor_options' => [ |
| 561 |
'title' => __('Multiple Choice', 'fluentform'), |
| 562 |
'icon_class' => 'ff-edit-multiple-choice', |
| 563 |
'element' => 'select', |
| 564 |
'template' => 'select' |
| 565 |
] |
| 566 |
], |
| 567 |
'input_checkbox' => [ |
| 568 |
'index' => $args['index'], |
| 569 |
'element' => 'input_checkbox', |
| 570 |
'attributes' => [ |
| 571 |
'name' => $args['name'], |
| 572 |
'value' => $args['value'], |
| 573 |
'class' => $args['class'], |
| 574 |
'id' => '', |
| 575 |
'type' => 'checkbox' |
| 576 |
], |
| 577 |
'settings' => [ |
| 578 |
'container_class' => '', |
| 579 |
'label_placement' => $args['label_placement'], |
| 580 |
'label' => $args['label'], |
| 581 |
'help_message' => $args['help_message'], |
| 582 |
'advanced_options' => $args['options'], |
| 583 |
'calc_value_status' => $args['calc_value_status'], |
| 584 |
'enable_image_input' => $args['enable_image_input'], |
| 585 |
'randomize_options' => 'no', |
| 586 |
'validation_rules' => [ |
| 587 |
'required' => [ |
| 588 |
'value' => $args['required'], |
| 589 |
'message' => __('This field is required', 'fluentform'), |
| 590 |
], |
| 591 |
], |
| 592 |
'conditional_logics' => [], |
| 593 |
'layout_class' => $args['layout_class'] |
| 594 |
], |
| 595 |
'editor_options' => [ |
| 596 |
'title' => __('Checkbox', 'fluentform'), |
| 597 |
'icon_class' => 'ff-edit-checkbox-1', |
| 598 |
'template' => 'inputCheckable' |
| 599 |
], |
| 600 |
'uniqElKey' => $args['uniqElKey'], |
| 601 |
], |
| 602 |
'input_radio' => [ |
| 603 |
'index' => $args['index'], |
| 604 |
'element' => 'input_radio', |
| 605 |
'attributes' => [ |
| 606 |
'name' => $args['name'], |
| 607 |
'value' => $args['value'], |
| 608 |
'class' => $args['class'], |
| 609 |
'type' => 'radio', |
| 610 |
], |
| 611 |
'settings' => [ |
| 612 |
'dynamic_default_value' => $args['dynamic_default_value'], |
| 613 |
'container_class' => '', |
| 614 |
'admin_field_label' => $args['admin_field_label'], |
| 615 |
'label_placement' => $args['label_placement'], |
| 616 |
'display_type' => '', |
| 617 |
'randomize_options' => 'no', |
| 618 |
'label' => $args['label'], |
| 619 |
'help_message' => $args['help_message'], |
| 620 |
'advanced_options' => $args['options'], |
| 621 |
'layout_class' => $args['layout_class'], |
| 622 |
'calc_value_status' => $args['calc_value_status'], |
| 623 |
'enable_image_input' => $args['enable_image_input'], |
| 624 |
'validation_rules' => [ |
| 625 |
'required' => [ |
| 626 |
'value' => $args['required'], |
| 627 |
'message' => __('This field is required', 'fluentform'), |
| 628 |
], |
| 629 |
], |
| 630 |
'conditional_logics' => [], |
| 631 |
], |
| 632 |
'editor_options' => [ |
| 633 |
'title' => __('Radio Field', 'fluentform'), |
| 634 |
'icon_class' => 'ff-edit-radio', |
| 635 |
'element' => 'input-radio', |
| 636 |
'template' => 'inputCheckable' |
| 637 |
], |
| 638 |
'uniqElKey' => $args['uniqElKey'], |
| 639 |
], |
| 640 |
'input_date' => [ |
| 641 |
'element' => 'input_date', |
| 642 |
'index' => $args['index'], |
| 643 |
'attributes' => [ |
| 644 |
'name' => $args['name'], |
| 645 |
'value' => '', |
| 646 |
'type' => 'text', |
| 647 |
'class' => $args['class'], |
| 648 |
'placeholder' => $args['placeholder'], |
| 649 |
'id' => '', |
| 650 |
], |
| 651 |
'settings' => [ |
| 652 |
'container_class' => '', |
| 653 |
'label_placement' => $args['label_placement'], |
| 654 |
'admin_field_label' => $args['admin_field_label'], |
| 655 |
'label' => $args['label'], |
| 656 |
'help_message' => $args['help_message'], |
| 657 |
'date_format' => $args['format'], |
| 658 |
'is_time_enabled' => $args['is_time_enabled'], |
| 659 |
'validation_rules' => [ |
| 660 |
'required' => [ |
| 661 |
'value' => $args['required'], |
| 662 |
'message' => 'This field is required' |
| 663 |
] |
| 664 |
], |
| 665 |
], |
| 666 |
'editor_options' => [ |
| 667 |
'title' => 'Time & Date', |
| 668 |
'icon_class' => 'ff-edit-date', |
| 669 |
'template' => 'inputText', |
| 670 |
], |
| 671 |
'uniqElKey' => $args['uniqElKey'], |
| 672 |
], |
| 673 |
'input_mask' => [ |
| 674 |
'index' => $args['index'], |
| 675 |
'element' => 'input_text', |
| 676 |
'attributes' => [ |
| 677 |
'type' => 'text', |
| 678 |
'name' => $args['name'], |
| 679 |
'value' => $args['value'], |
| 680 |
'class' => $args['class'], |
| 681 |
'id' => $args['id'], |
| 682 |
'placeholder' => $args['placeholder'], |
| 683 |
'data-mask' => $args['mask'], |
| 684 |
], |
| 685 |
'settings' => [ |
| 686 |
'container_class' => '', |
| 687 |
'label' => $args['label'], |
| 688 |
'label_placement' => $args['label_placement'], |
| 689 |
'admin_field_label' => $args['admin_field_label'], |
| 690 |
'help_message' => $args['help_message'], |
| 691 |
'prefix_label' => '', |
| 692 |
'suffix_label' => '', |
| 693 |
'temp_mask' => $args['temp_mask'], |
| 694 |
'data-mask-reverse' => 'no', |
| 695 |
'data-clear-if-not-match' => 'no', |
| 696 |
'validation_rules' => [ |
| 697 |
'required' => [ |
| 698 |
'value' => $args['required'], |
| 699 |
'message' => __('This field is required', 'fluentform'), |
| 700 |
] |
| 701 |
], |
| 702 |
'conditional_logics' => [], |
| 703 |
], |
| 704 |
'editor_options' => [ |
| 705 |
'title' => __('Mask Input', 'fluentform'), |
| 706 |
'icon_class' => 'ff-edit-mask', |
| 707 |
'template' => 'inputText' |
| 708 |
], |
| 709 |
'uniqElKey' => $args['uniqElKey'], |
| 710 |
], |
| 711 |
'input_password' => [ |
| 712 |
'index' => $args['index'], |
| 713 |
'element' => 'input_password', |
| 714 |
'attributes' => [ |
| 715 |
'type' => 'password', |
| 716 |
'name' => $args['name'], |
| 717 |
'value' => $args['value'], |
| 718 |
'class' => $args['class'], |
| 719 |
'id' => $args['id'], |
| 720 |
'placeholder' => $args['placeholder'], |
| 721 |
], |
| 722 |
'settings' => [ |
| 723 |
'container_class' => $args['container_class'], |
| 724 |
'label' => $args['label'], |
| 725 |
'label_placement' => $args['label_placement'], |
| 726 |
'admin_field_label' => $args['admin_field_label'], |
| 727 |
'help_message' => $args['help_message'], |
| 728 |
'conditional_logics' => [], |
| 729 |
'validation_rules' => [ |
| 730 |
'required' => [ |
| 731 |
'value' => $args['required'], |
| 732 |
'message' => 'This field is required' |
| 733 |
] |
| 734 |
], |
| 735 |
], |
| 736 |
'editor_options' => [ |
| 737 |
'title' => __('Password Field', 'fluentform'), |
| 738 |
'icon_class' => 'ff-edit-password', |
| 739 |
'template' => 'inputText', |
| 740 |
], |
| 741 |
'uniqElKey' => $args['uniqElKey'], |
| 742 |
], |
| 743 |
'input_number' => [ |
| 744 |
'index' => $args['index'], |
| 745 |
'element' => 'input_number', |
| 746 |
'attributes' => [ |
| 747 |
'type' => 'number', |
| 748 |
'name' => $args['name'], |
| 749 |
'value' => $args['value'], |
| 750 |
'id' => '', |
| 751 |
'class' => $args['class'], |
| 752 |
'placeholder' => $args['placeholder'] |
| 753 |
], |
| 754 |
'settings' => [ |
| 755 |
'container_class' => '', |
| 756 |
'label' => $args['label'], |
| 757 |
'admin_field_label' => $args['admin_field_label'], |
| 758 |
'label_placement' => $args['label_placement'], |
| 759 |
'help_message' => $args['help_message'], |
| 760 |
'number_step' => $args['step'], |
| 761 |
'prefix_label' => $args['prefix'], |
| 762 |
'suffix_label' => $args['suffix'], |
| 763 |
'numeric_formatter' => '', |
| 764 |
'validation_rules' => [ |
| 765 |
'required' => [ |
| 766 |
'value' => $args['required'], |
| 767 |
'message' => __('This field is required', 'fluentform'), |
| 768 |
], |
| 769 |
'numeric' => [ |
| 770 |
'value' => true, |
| 771 |
'message' => __('This field must contain numeric value', 'fluentform'), |
| 772 |
], |
| 773 |
'min' => [ |
| 774 |
'value' => $args['min'], |
| 775 |
'message' => 'Minimum value is ' . $args['min'], |
| 776 |
], |
| 777 |
'max' => [ |
| 778 |
'value' => $args['max'], |
| 779 |
'message' => 'Maximum value is ' . $args['max'], |
| 780 |
], |
| 781 |
], |
| 782 |
'conditional_logics' => [], |
| 783 |
'calculation_settings' => [ |
| 784 |
'status' => $args['enable_calculation'], |
| 785 |
'formula' => $args['calculation_formula'] |
| 786 |
], |
| 787 |
], |
| 788 |
'editor_options' => [ |
| 789 |
'title' => __('Numeric Field', 'fluentform'), |
| 790 |
'icon_class' => 'ff-edit-numeric', |
| 791 |
'template' => 'inputText' |
| 792 |
], |
| 793 |
'uniqElKey' => $args['uniqElKey'], |
| 794 |
], |
| 795 |
'phone' => [ |
| 796 |
'index' => $args['index'], |
| 797 |
'element' => 'phone', |
| 798 |
'attributes' => [ |
| 799 |
'name' => $args['name'], |
| 800 |
'value' => $args['value'], |
| 801 |
'id' => $args['id'], |
| 802 |
'class' => $args['class'], |
| 803 |
'placeholder' => $args['placeholder'], |
| 804 |
'type' => 'tel' |
| 805 |
], |
| 806 |
'settings' => [ |
| 807 |
'container_class' => '', |
| 808 |
'placeholder' => '', |
| 809 |
// 'int_tel_number' => 'no', |
| 810 |
'auto_select_country' => 'no', |
| 811 |
'label' => $args['label'], |
| 812 |
'label_placement' => $args['label_placement'], |
| 813 |
'help_message' => $args['help_message'], |
| 814 |
'admin_field_label' => $args['admin_field_label'], |
| 815 |
'phone_country_list' => array( |
| 816 |
'active_list' => 'all', |
| 817 |
'visible_list' => array(), |
| 818 |
'hidden_list' => array(), |
| 819 |
), |
| 820 |
'default_country' => '', |
| 821 |
'validation_rules' => [ |
| 822 |
'required' => [ |
| 823 |
'value' => $args['required'], |
| 824 |
'message' => __('This field is required', 'fluentform'), |
| 825 |
], |
| 826 |
'valid_phone_number' => [ |
| 827 |
'value' => ArrayHelper::isTrue($args, 'valid_phone_number'), |
| 828 |
'message' => __('Phone number is not valid', 'fluentform') |
| 829 |
] |
| 830 |
], |
| 831 |
'conditional_logics' => [] |
| 832 |
], |
| 833 |
'editor_options' => [ |
| 834 |
'title' => 'Phone Field', |
| 835 |
'icon_class' => 'el-icon-phone-outline', |
| 836 |
'template' => 'inputText' |
| 837 |
], |
| 838 |
'uniqElKey' => $args['uniqElKey'], |
| 839 |
|
| 840 |
], |
| 841 |
'input_file' => [ |
| 842 |
'index' => $args['index'], |
| 843 |
'element' => 'input_file', |
| 844 |
'attributes' => [ |
| 845 |
'type' => 'file', |
| 846 |
'name' => $args['name'], |
| 847 |
'value' => '', |
| 848 |
'id' => $args['id'], |
| 849 |
'class' => $args['class'], |
| 850 |
], |
| 851 |
'settings' => [ |
| 852 |
'container_class' => '', |
| 853 |
'label' => $args['label'], |
| 854 |
'admin_field_label' => $args['admin_field_label'], |
| 855 |
'label_placement' => $args['label_placement'], |
| 856 |
'btn_text' => $args['upload_btn_text'], |
| 857 |
'help_message' => $args['help_message'], |
| 858 |
'validation_rules' => [ |
| 859 |
'required' => [ |
| 860 |
'value' => $args['required'], |
| 861 |
'message' => __('This field is required', 'fluentform'), |
| 862 |
], |
| 863 |
'max_file_size' => [ |
| 864 |
'value' => $args['max_file_size'], |
| 865 |
'_valueFrom' => $args['max_size_unit'], |
| 866 |
'message' => __('Maximum file size limit reached', 'fluentform') |
| 867 |
], |
| 868 |
'max_file_count' => [ |
| 869 |
'value' => $args['max_file_count'], |
| 870 |
'message' => __('Maximum upload limit reached', 'fluentform') |
| 871 |
], |
| 872 |
'allowed_file_types' => [ |
| 873 |
'value' => $args['allowed_file_types'], |
| 874 |
'message' => __('Invalid file type', 'fluentform') |
| 875 |
] |
| 876 |
], |
| 877 |
'conditional_logics' => [], |
| 878 |
], |
| 879 |
'editor_options' => [ |
| 880 |
'title' => __('File Upload', 'fluentform'), |
| 881 |
'icon_class' => 'ff-edit-files', |
| 882 |
'template' => 'inputFile' |
| 883 |
], |
| 884 |
'uniqElKey' => $args['uniqElKey'], |
| 885 |
], |
| 886 |
'custom_html' => [ |
| 887 |
'index' => $args['index'], |
| 888 |
'element' => 'custom_html', |
| 889 |
'attributes' => [], |
| 890 |
'settings' => [ |
| 891 |
'html_codes' => $args['html_codes'], |
| 892 |
'conditional_logics' => [], |
| 893 |
'container_class' => ArrayHelper::get($args, 'container_class', '') |
| 894 |
], |
| 895 |
'editor_options' => [ |
| 896 |
'title' => __('Custom HTML', 'fluentform'), |
| 897 |
'icon_class' => 'ff-edit-html', |
| 898 |
'template' => 'customHTML', |
| 899 |
], |
| 900 |
'uniqElKey' => $args['uniqElKey'], |
| 901 |
], |
| 902 |
'section_break' => [ |
| 903 |
'index' => $args['index'], |
| 904 |
'element' => 'section_break', |
| 905 |
'attributes' => [ |
| 906 |
'id' => $args['id'], |
| 907 |
'class' => $args['class'], |
| 908 |
], |
| 909 |
'settings' => [ |
| 910 |
'label' => $args['label'], |
| 911 |
'description' => $args['section_break_desc'], |
| 912 |
'align' => 'left', |
| 913 |
'conditional_logics' => [], |
| 914 |
], |
| 915 |
'editor_options' => [ |
| 916 |
'title' => __('Section Break', 'fluentform'), |
| 917 |
'icon_class' => 'ff-edit-section-break', |
| 918 |
'template' => 'sectionBreak', |
| 919 |
], |
| 920 |
'uniqElKey' => $args['uniqElKey'], |
| 921 |
], |
| 922 |
'rangeslider' => [ |
| 923 |
'index' => $args['index'], |
| 924 |
'element' => 'rangeslider', |
| 925 |
'attributes' => [ |
| 926 |
'type' => 'range', |
| 927 |
'name' => $args['name'], |
| 928 |
'value' => $args['value'], |
| 929 |
'id' => $args['id'], |
| 930 |
'class' => $args['class'], |
| 931 |
'min' => $args['min'], |
| 932 |
'max' => $args['max'], |
| 933 |
], |
| 934 |
'settings' => [ |
| 935 |
'number_step' => $args['step'], |
| 936 |
'label' => $args['label'], |
| 937 |
'help_message' => $args['help_message'], |
| 938 |
'label_placement' => $args['label_placement'], |
| 939 |
'admin_field_label' => $args['admin_field_label'], |
| 940 |
'container_class' => '', |
| 941 |
'conditional_logics' => [], |
| 942 |
'validation_rules' => [ |
| 943 |
'required' => [ |
| 944 |
'value' => $args['required'], |
| 945 |
'message' => 'This field is required' |
| 946 |
] |
| 947 |
], |
| 948 |
], |
| 949 |
'editor_options' => [ |
| 950 |
'title' => 'Range Slider', |
| 951 |
'icon_class' => 'dashicons dashicons-leftright', |
| 952 |
'template' => 'inputSlider' |
| 953 |
], |
| 954 |
'uniqElKey' => $args['uniqElKey'], |
| 955 |
], |
| 956 |
'ratings' => [ |
| 957 |
'index' => $args['index'], |
| 958 |
'element' => 'ratings', |
| 959 |
'attributes' => [ |
| 960 |
'class' => $args['class'], |
| 961 |
'value' => 0, |
| 962 |
'name' => $args['name'], |
| 963 |
], |
| 964 |
'settings' => [ |
| 965 |
'label' => $args['label'], |
| 966 |
'show_text' => 'no', |
| 967 |
'help_message' => $args['help_message'], |
| 968 |
'label_placement' => $args['label_placement'], |
| 969 |
'admin_field_label' => $args['admin_field_label'], |
| 970 |
'container_class' => '', |
| 971 |
'conditional_logics' => [], |
| 972 |
'validation_rules' => [ |
| 973 |
'required' => [ |
| 974 |
'value' => $args['required'], |
| 975 |
'message' => __('This field is required', 'fluentform'), |
| 976 |
], |
| 977 |
], |
| 978 |
], |
| 979 |
'options' => $args['options'], |
| 980 |
'editor_options' => [ |
| 981 |
'title' => __('Ratings', 'fluentform'), |
| 982 |
'icon_class' => 'ff-edit-rating', |
| 983 |
'template' => 'ratings', |
| 984 |
], |
| 985 |
'uniqElKey' => $args['uniqElKey'], |
| 986 |
], |
| 987 |
'gdpr_agreement' => [ |
| 988 |
'index' => $args['index'], |
| 989 |
'element' => 'gdpr_agreement', |
| 990 |
'attributes' => [ |
| 991 |
'type' => 'checkbox', |
| 992 |
'name' => $args['name'], |
| 993 |
'value' => false, |
| 994 |
'class' => $args['class'] . ' ff_gdpr_field', |
| 995 |
], |
| 996 |
'settings' => [ |
| 997 |
'label' => $args['label'], |
| 998 |
'tnc_html' => $args['tnc_html'], |
| 999 |
'admin_field_label' => __('GDPR Agreement', 'fluentform'), |
| 1000 |
'has_checkbox' => true, |
| 1001 |
'container_class' => '', |
| 1002 |
'validation_rules' => [ |
| 1003 |
'required' => [ |
| 1004 |
'value' => true, |
| 1005 |
'message' => __('This field is required', 'fluentform'), |
| 1006 |
], |
| 1007 |
], |
| 1008 |
'required_field_message' => '', |
| 1009 |
'conditional_logics' => [], |
| 1010 |
], |
| 1011 |
'editor_options' => [ |
| 1012 |
'title' => __('GDPR Agreement', 'fluentform'), |
| 1013 |
'icon_class' => 'ff-edit-gdpr', |
| 1014 |
'template' => 'termsCheckbox' |
| 1015 |
], |
| 1016 |
'uniqElKey' => $args['uniqElKey'], |
| 1017 |
], |
| 1018 |
'form_step' => [ |
| 1019 |
'index' => $args['index'], |
| 1020 |
'element' => 'form_step', |
| 1021 |
'attributes' => [ |
| 1022 |
'id' => '', |
| 1023 |
'class' => $args['class'], |
| 1024 |
], |
| 1025 |
'settings' => [ |
| 1026 |
'prev_btn' => [ |
| 1027 |
'type' => ArrayHelper::get($args, 'prev_btn.type', 'default'), |
| 1028 |
'text' => ArrayHelper::get($args, 'prev_btn.text', 'Previous'), |
| 1029 |
'img_url' => ArrayHelper::get($args, 'prev_btn.img_url', '') |
| 1030 |
], |
| 1031 |
'next_btn' => [ |
| 1032 |
'type' => ArrayHelper::get($args, 'next_btn.type', 'default'), |
| 1033 |
'text' => ArrayHelper::get($args, 'next_btn.text', 'Next'), |
| 1034 |
'img_url' => ArrayHelper::get($args, 'next_btn.img_url', '') |
| 1035 |
] |
| 1036 |
], |
| 1037 |
'editor_options' => [ |
| 1038 |
'title' => 'Form Step', |
| 1039 |
'icon_class' => 'ff-edit-step', |
| 1040 |
'template' => 'formStep' |
| 1041 |
], |
| 1042 |
'uniqElKey' => $args['uniqElKey'], |
| 1043 |
], |
| 1044 |
'select_country' => [ |
| 1045 |
'index' => $args['index'], |
| 1046 |
'element' => 'select_country', |
| 1047 |
'attributes' => [ |
| 1048 |
'name' => $args['name'], |
| 1049 |
'value' => $args['value'], |
| 1050 |
'id' => $args['id'], |
| 1051 |
'class' => $args['class'], |
| 1052 |
'placeholder' => $args['placeholder'], |
| 1053 |
], |
| 1054 |
'settings' => [ |
| 1055 |
'container_class' => $args['container_class'], |
| 1056 |
'label' => $args['label'], |
| 1057 |
'admin_field_label' => '', |
| 1058 |
'label_placement' => $args['label_placement'], |
| 1059 |
'help_message' => $args['help_message'], |
| 1060 |
'enable_select_2' => 'no', |
| 1061 |
'validation_rules' => [ |
| 1062 |
'required' => [ |
| 1063 |
'value' => $args['required'], |
| 1064 |
'message' => __('This field is required', 'fluentform'), |
| 1065 |
], |
| 1066 |
], |
| 1067 |
'country_list' => [ |
| 1068 |
'active_list' => 'all', |
| 1069 |
'visible_list' => [], |
| 1070 |
'hidden_list' => [], |
| 1071 |
], |
| 1072 |
'conditional_logics' => [], |
| 1073 |
], |
| 1074 |
'options' => [ |
| 1075 |
'US' => 'United States of America', |
| 1076 |
], |
| 1077 |
'editor_options' => [ |
| 1078 |
'title' => __('Country List', 'fluentform'), |
| 1079 |
'element' => 'country-list', |
| 1080 |
'icon_class' => 'ff-edit-country', |
| 1081 |
'template' => 'selectCountry' |
| 1082 |
], |
| 1083 |
'uniqElKey' => $args['uniqElKey'], |
| 1084 |
], |
| 1085 |
'repeater_field' => [ |
| 1086 |
'index' => $args['index'], |
| 1087 |
'element' => 'repeater_field', |
| 1088 |
'attributes' => array( |
| 1089 |
'name' => $args['name'], |
| 1090 |
'data-type' => 'repeater_field' |
| 1091 |
), |
| 1092 |
'fields' => $args['fields'], |
| 1093 |
'settings' => array( |
| 1094 |
'label' => $args['label'], |
| 1095 |
'admin_field_label' => '', |
| 1096 |
'container_class' => '', |
| 1097 |
'label_placement' => '', |
| 1098 |
'validation_rules' => array(), |
| 1099 |
'conditional_logics' => array(), |
| 1100 |
'max_repeat_field' => '' |
| 1101 |
), |
| 1102 |
'editor_options' => array( |
| 1103 |
'title' => 'Repeat Field', |
| 1104 |
'icon_class' => 'ff-edit-repeat', |
| 1105 |
'template' => 'fieldsRepeatSettings' |
| 1106 |
), |
| 1107 |
'uniqElKey' => $args['uniqElKey'], |
| 1108 |
], |
| 1109 |
'reCaptcha' => [ |
| 1110 |
'index' => $args['index'], |
| 1111 |
'element' => 'recaptcha', |
| 1112 |
'attributes' => ['name' => 'recaptcha'], |
| 1113 |
'settings' => [ |
| 1114 |
'label' => $args['label'], |
| 1115 |
'label_placement' => $args['label_placement'], |
| 1116 |
'validation_rules' => [], |
| 1117 |
], |
| 1118 |
'editor_options' => [ |
| 1119 |
'title' => __('reCaptcha', 'fluentform'), |
| 1120 |
'icon_class' => 'ff-edit-recaptha', |
| 1121 |
'why_disabled_modal' => 'recaptcha', |
| 1122 |
'template' => 'recaptcha', |
| 1123 |
], |
| 1124 |
'uniqElKey' => $args['uniqElKey'], |
| 1125 |
], |
| 1126 |
'terms_and_condition' => [ |
| 1127 |
'index' => $args['index'], |
| 1128 |
'element' => 'terms_and_condition', |
| 1129 |
'attributes' => [ |
| 1130 |
'type' => 'checkbox', |
| 1131 |
'name' => $args['name'], |
| 1132 |
'value' => false, |
| 1133 |
'class' => $args['class'], |
| 1134 |
], |
| 1135 |
'settings' => [ |
| 1136 |
'tnc_html' => $args['tnc_html'], |
| 1137 |
'has_checkbox' => true, |
| 1138 |
'admin_field_label' => __('Terms and Conditions', 'fluentform'), |
| 1139 |
'container_class' => '', |
| 1140 |
'validation_rules' => [ |
| 1141 |
'required' => [ |
| 1142 |
'value' => $args['required'], |
| 1143 |
'message' => __('This field is required', 'fluentform'), |
| 1144 |
], |
| 1145 |
], |
| 1146 |
'conditional_logics' => [], |
| 1147 |
], |
| 1148 |
'editor_options' => [ |
| 1149 |
'title' => __('Terms & Conditions', 'fluentform'), |
| 1150 |
'icon_class' => 'ff-edit-terms-condition', |
| 1151 |
'template' => 'termsCheckbox' |
| 1152 |
], |
| 1153 |
], |
| 1154 |
'address' => [ |
| 1155 |
'index' => $args['index'], |
| 1156 |
'element' => 'address', |
| 1157 |
'attributes' => [ |
| 1158 |
'id' => '', |
| 1159 |
'class' => $args['class'], |
| 1160 |
'name' => $args['name'], |
| 1161 |
'data-type' => 'address-element' |
| 1162 |
], |
| 1163 |
'settings' => [ |
| 1164 |
'label' => $args['label'], |
| 1165 |
'admin_field_label' => 'Address', |
| 1166 |
'conditional_logics' => [], |
| 1167 |
], |
| 1168 |
'fields' => [ |
| 1169 |
'address_line_1' => [ |
| 1170 |
'element' => 'input_text', |
| 1171 |
'attributes' => [ |
| 1172 |
'type' => 'text', |
| 1173 |
'name' => ArrayHelper::get($args, 'address_args.address_line_1.name'), |
| 1174 |
'value' => ArrayHelper::get($args, 'address_args.address_line_1.default', ''), |
| 1175 |
'id' => '', |
| 1176 |
'class' => '', |
| 1177 |
'placeholder' => ArrayHelper::get($args, 'address_args.address_line_1.placeholder', __('Address Line 1', 'fluentform')), |
| 1178 |
], |
| 1179 |
'settings' => [ |
| 1180 |
'container_class' => '', |
| 1181 |
'label' => ArrayHelper::get($args, 'address_args.address_line_1.label'), |
| 1182 |
'admin_field_label' => '', |
| 1183 |
'help_message' => '', |
| 1184 |
'visible' => ArrayHelper::get($args, 'address_args.address_line_1.visible'), |
| 1185 |
'validation_rules' => [ |
| 1186 |
'required' => [ |
| 1187 |
'value' => ArrayHelper::isTrue($args, 'address_args.address_line_1.required'), |
| 1188 |
'message' => __('This field is required', 'fluentform'), |
| 1189 |
], |
| 1190 |
], |
| 1191 |
'conditional_logics' => [], |
| 1192 |
], |
| 1193 |
'editor_options' => [ |
| 1194 |
'template' => 'inputText' |
| 1195 |
], |
| 1196 |
], |
| 1197 |
'address_line_2' => [ |
| 1198 |
'element' => 'input_text', |
| 1199 |
'attributes' => [ |
| 1200 |
'type' => 'text', |
| 1201 |
'name' => ArrayHelper::get($args, 'address_args.address_line_2.name'), |
| 1202 |
'value' => ArrayHelper::get($args, 'address_args.address_line_2.default', ''), |
| 1203 |
'id' => '', |
| 1204 |
'class' => '', |
| 1205 |
'placeholder' => ArrayHelper::get($args, 'address_args.address_line_2.placeholder', __('Address Line 2', 'fluentform')), |
| 1206 |
], |
| 1207 |
'settings' => [ |
| 1208 |
'container_class' => '', |
| 1209 |
'label' => ArrayHelper::get($args, 'address_args.address_line_2.label'), |
| 1210 |
'admin_field_label' => '', |
| 1211 |
'help_message' => '', |
| 1212 |
'visible' => ArrayHelper::get($args, 'address_args.address_line_2.visible'), |
| 1213 |
'validation_rules' => [ |
| 1214 |
'required' => [ |
| 1215 |
'value' => ArrayHelper::isTrue($args, 'address_args.address_line_2.required'), |
| 1216 |
'message' => __('This field is required', 'fluentform'), |
| 1217 |
], |
| 1218 |
], |
| 1219 |
'conditional_logics' => [], |
| 1220 |
], |
| 1221 |
'editor_options' => [ |
| 1222 |
'template' => 'inputText' |
| 1223 |
], |
| 1224 |
], |
| 1225 |
'city' => [ |
| 1226 |
'element' => 'input_text', |
| 1227 |
'attributes' => [ |
| 1228 |
'type' => 'text', |
| 1229 |
'name' => ArrayHelper::get($args, 'address_args.city.name'), |
| 1230 |
'value' => ArrayHelper::get($args, 'address_args.city.default', ''), |
| 1231 |
'id' => '', |
| 1232 |
'class' => '', |
| 1233 |
'placeholder' => ArrayHelper::get($args, 'address_args.city.placeholder', __('City', 'fluentform')), |
| 1234 |
], |
| 1235 |
'settings' => [ |
| 1236 |
'container_class' => '', |
| 1237 |
'label' => ArrayHelper::get($args, 'address_args.city.label'), |
| 1238 |
'admin_field_label' => '', |
| 1239 |
'help_message' => '', |
| 1240 |
'error_message' => '', |
| 1241 |
'visible' => ArrayHelper::get($args, 'address_args.city.visible'), |
| 1242 |
'validation_rules' => [ |
| 1243 |
'required' => [ |
| 1244 |
'value' => ArrayHelper::isTrue($args, 'address_args.city.required'), |
| 1245 |
'message' => __('This field is required', 'fluentform'), |
| 1246 |
], |
| 1247 |
], |
| 1248 |
'conditional_logics' => [], |
| 1249 |
], |
| 1250 |
'editor_options' => [ |
| 1251 |
'template' => 'inputText' |
| 1252 |
], |
| 1253 |
], |
| 1254 |
'state' => [ |
| 1255 |
'element' => 'input_text', |
| 1256 |
'attributes' => [ |
| 1257 |
'type' => 'text', |
| 1258 |
'name' => ArrayHelper::get($args, 'address_args.state.name'), |
| 1259 |
'value' => ArrayHelper::get($args, 'address_args.state.default', ''), |
| 1260 |
'id' => '', |
| 1261 |
'class' => '', |
| 1262 |
'placeholder' => ArrayHelper::get($args, 'address_args.state.placeholder', __('State', 'fluentform')), |
| 1263 |
], |
| 1264 |
'settings' => [ |
| 1265 |
'container_class' => '', |
| 1266 |
'label' => ArrayHelper::get($args, 'address_args.state.label'), |
| 1267 |
'admin_field_label' => '', |
| 1268 |
'help_message' => '', |
| 1269 |
'error_message' => '', |
| 1270 |
'visible' => ArrayHelper::get($args, 'address_args.state.visible'), |
| 1271 |
'validation_rules' => [ |
| 1272 |
'required' => [ |
| 1273 |
'value' => ArrayHelper::isTrue($args, 'address_args.state.required'), |
| 1274 |
'message' => __('This field is required', 'fluentform'), |
| 1275 |
], |
| 1276 |
], |
| 1277 |
'conditional_logics' => [], |
| 1278 |
], |
| 1279 |
'editor_options' => [ |
| 1280 |
'template' => 'inputText' |
| 1281 |
], |
| 1282 |
], |
| 1283 |
'zip' => [ |
| 1284 |
'element' => 'input_text', |
| 1285 |
'attributes' => [ |
| 1286 |
'type' => 'text', |
| 1287 |
'name' => ArrayHelper::get($args, 'address_args.zip.name'), |
| 1288 |
'value' => ArrayHelper::get($args, 'address_args.zip.default', ''), |
| 1289 |
'id' => '', |
| 1290 |
'class' => '', |
| 1291 |
'placeholder' => ArrayHelper::get($args, 'address_args.zip.placeholder', __('Zip', 'fluentform')), |
| 1292 |
'required' => false, |
| 1293 |
], |
| 1294 |
'settings' => [ |
| 1295 |
'container_class' => '', |
| 1296 |
'label' => ArrayHelper::get($args, 'address_args.zip.label'), |
| 1297 |
'admin_field_label' => '', |
| 1298 |
'help_message' => '', |
| 1299 |
'error_message' => '', |
| 1300 |
'visible' => ArrayHelper::get($args, 'address_args.zip.visible'), |
| 1301 |
'validation_rules' => [ |
| 1302 |
'required' => [ |
| 1303 |
'value' => ArrayHelper::isTrue($args, 'address_args.zip.required'), |
| 1304 |
'message' => __('This field is required', 'fluentform'), |
| 1305 |
], |
| 1306 |
], |
| 1307 |
'conditional_logics' => [], |
| 1308 |
], |
| 1309 |
'editor_options' => [ |
| 1310 |
'template' => 'inputText' |
| 1311 |
], |
| 1312 |
], |
| 1313 |
'country' => [ |
| 1314 |
'element' => 'select_country', |
| 1315 |
'attributes' => [ |
| 1316 |
'name' => ArrayHelper::get($args, 'address_args.country.name'), |
| 1317 |
'value' => ArrayHelper::get($args, 'address_args.country.default', ''), |
| 1318 |
'id' => '', |
| 1319 |
'class' => '', |
| 1320 |
'placeholder' => ArrayHelper::get($args, 'address_args.country.placeholder', __('Country', 'fluentform')), |
| 1321 |
'required' => false, |
| 1322 |
], |
| 1323 |
'settings' => [ |
| 1324 |
'container_class' => '', |
| 1325 |
'label' => ArrayHelper::get($args, 'address_args.country.label'), |
| 1326 |
'admin_field_label' => '', |
| 1327 |
'help_message' => '', |
| 1328 |
'error_message' => '', |
| 1329 |
'visible' => ArrayHelper::get($args, 'address_args.country.visible'), |
| 1330 |
'validation_rules' => [ |
| 1331 |
'required' => [ |
| 1332 |
'value' => ArrayHelper::isTrue($args, 'address_args.country.required'), |
| 1333 |
'message' => __('This field is required', 'fluentform'), |
| 1334 |
], |
| 1335 |
], |
| 1336 |
'country_list' => [ |
| 1337 |
'active_list' => 'all', |
| 1338 |
'visible_list' => [], |
| 1339 |
'hidden_list' => [], |
| 1340 |
], |
| 1341 |
'conditional_logics' => [], |
| 1342 |
], |
| 1343 |
'options' => [ |
| 1344 |
'US' => 'US of America', |
| 1345 |
'UK' => 'United Kingdom' |
| 1346 |
], |
| 1347 |
'editor_options' => [ |
| 1348 |
'title' => 'Country List', |
| 1349 |
'element' => 'country-list', |
| 1350 |
'icon_class' => 'icon-text-width', |
| 1351 |
'template' => 'selectCountry' |
| 1352 |
], |
| 1353 |
], |
| 1354 |
], |
| 1355 |
'editor_options' => [ |
| 1356 |
'title' => __('Address Fields', 'fluentform'), |
| 1357 |
'element' => 'address-fields', |
| 1358 |
'icon_class' => 'ff-edit-address', |
| 1359 |
'template' => 'addressFields' |
| 1360 |
], |
| 1361 |
], |
| 1362 |
'rich_text_input' => [ |
| 1363 |
'index' => $args['index'], |
| 1364 |
'element' => 'rich_text_input', |
| 1365 |
'attributes' => [ |
| 1366 |
'name' => $args['name'], |
| 1367 |
'value' => $args['value'], |
| 1368 |
'id' => '', |
| 1369 |
'class' => $args['class'], |
| 1370 |
'placeholder' => $args['placeholder'], |
| 1371 |
'rows' => ArrayHelper::get($args, 'rows', 3), |
| 1372 |
'cols' => ArrayHelper::get($args, 'cols', 2), |
| 1373 |
'maxlength' => ArrayHelper::get($args, 'maxlength', ''), |
| 1374 |
], |
| 1375 |
'settings' => [ |
| 1376 |
'container_class' => $args['container_class'], |
| 1377 |
'placeholder' => $args['placeholder'], |
| 1378 |
'label_placement' => $args['label_placement'], |
| 1379 |
'admin_field_label' => $args['admin_field_label'], |
| 1380 |
'label' => $args['label'], |
| 1381 |
'help_message' => $args['help_message'], |
| 1382 |
'validation_rules' => [ |
| 1383 |
'required' => [ |
| 1384 |
'value' => ArrayHelper::isTrue($args,'required'), |
| 1385 |
'message' => __('This field is required', 'fluentform'), |
| 1386 |
] |
| 1387 |
], |
| 1388 |
'conditional_logics' => [] |
| 1389 |
], |
| 1390 |
'editor_options' => [ |
| 1391 |
'title' => __('Rich Text Input', 'fluentform'), |
| 1392 |
'icon_class' => 'ff-edit-textarea', |
| 1393 |
'template' => 'inputTextarea' |
| 1394 |
], |
| 1395 |
], |
| 1396 |
]; |
| 1397 |
if (!defined('FLUENTFORMPRO')) { |
| 1398 |
$proElements = ['repeater_field', 'rangeslider', 'color_picker', 'form_step', 'phone', 'input_file', 'rich_text_input']; |
| 1399 |
foreach ($proElements as $el) { |
| 1400 |
unset($defaultElements[$el]); |
| 1401 |
} |
| 1402 |
} |
| 1403 |
return $defaultElements; |
| 1404 |
} |
| 1405 |
|
| 1406 |
public function getSubmitBttn($args) |
| 1407 |
{ |
| 1408 |
return [ |
| 1409 |
'uniqElKey' => $args['uniqElKey'], |
| 1410 |
'element' => 'button', |
| 1411 |
'attributes' => [ |
| 1412 |
'type' => 'submit', |
| 1413 |
'class' => $args['class'] |
| 1414 |
], |
| 1415 |
'settings' => [ |
| 1416 |
'container_class' => '', |
| 1417 |
'align' => 'left', |
| 1418 |
'button_style' => 'default', |
| 1419 |
'button_size' => 'md', |
| 1420 |
'color' => '#ffffff', |
| 1421 |
'background_color' => '#1a7efb', |
| 1422 |
'button_ui' => [ |
| 1423 |
'type' => ArrayHelper::get($args, 'type', 'default'), |
| 1424 |
'text' => $args['label'], |
| 1425 |
'img_url' => ArrayHelper::get($args, 'img_url', '') |
| 1426 |
], |
| 1427 |
'normal_styles' => [], |
| 1428 |
'hover_styles' => [], |
| 1429 |
'current_state' => "normal_styles" |
| 1430 |
], |
| 1431 |
'editor_options' => [ |
| 1432 |
'title' => 'Submit Button', |
| 1433 |
], |
| 1434 |
|
| 1435 |
]; |
| 1436 |
|
| 1437 |
} |
| 1438 |
|
| 1439 |
abstract protected function getFormId($form); |
| 1440 |
|
| 1441 |
/** |
| 1442 |
* @param $metas |
| 1443 |
* @param $formId |
| 1444 |
*/ |
| 1445 |
protected function updateMetas($metas, $formId) |
| 1446 |
{ |
| 1447 |
if ($metas) { |
| 1448 |
//when multiple notifications |
| 1449 |
if ($notifications = ArrayHelper::get($metas, 'notifications')) { |
| 1450 |
(new \FluentForm\App\Modules\Form\Form(wpFluentForm()))->deleteMeta($formId, 'notifications'); |
| 1451 |
foreach ($notifications as $notify) { |
| 1452 |
$settings = [ |
| 1453 |
'form_id' => $formId, |
| 1454 |
'meta_key' => 'notifications', |
| 1455 |
'value' => json_encode($notify) |
| 1456 |
]; |
| 1457 |
|
| 1458 |
wpFluent()->table('fluentform_form_meta')->insert($settings); |
| 1459 |
} |
| 1460 |
unset($metas['notifications']); |
| 1461 |
} |
| 1462 |
//when multiple confirmations |
| 1463 |
if ($confirmations = ArrayHelper::get($metas, 'confirmations')) { |
| 1464 |
(new \FluentForm\App\Modules\Form\Form(wpFluentForm()))->deleteMeta($formId, 'confirmations'); |
| 1465 |
foreach ($confirmations as $confirmation) { |
| 1466 |
$settings = [ |
| 1467 |
'form_id' => $formId, |
| 1468 |
'meta_key' => 'confirmations', |
| 1469 |
'value' => json_encode($confirmation) |
| 1470 |
]; |
| 1471 |
|
| 1472 |
wpFluent()->table('fluentform_form_meta')->insert($settings); |
| 1473 |
} |
| 1474 |
unset($metas['confirmations']); |
| 1475 |
} |
| 1476 |
|
| 1477 |
//when have webhooks |
| 1478 |
if ($webhooks = ArrayHelper::get($metas, 'webhooks')) { |
| 1479 |
\FluentForm\App\Models\FormMeta::remove($formId, 'fluentform_webhook_feed'); |
| 1480 |
foreach ($webhooks as $webhook) { |
| 1481 |
\FluentForm\App\Models\FormMeta::create([ |
| 1482 |
'form_id' => $formId, |
| 1483 |
'meta_key' => 'fluentform_webhook_feed', |
| 1484 |
'value' => json_encode($webhook) |
| 1485 |
]); |
| 1486 |
} |
| 1487 |
unset($metas['webhooks']); |
| 1488 |
} |
| 1489 |
foreach ($metas as $metaKey => $metaData) { |
| 1490 |
(new \FluentForm\App\Modules\Form\Form(wpFluentForm()))->updateMeta($formId, $metaKey, $metaData); |
| 1491 |
} |
| 1492 |
} |
| 1493 |
} |
| 1494 |
|
| 1495 |
/** |
| 1496 |
* @param array $form |
| 1497 |
* @param array $insertedForms |
| 1498 |
* @param $formItem |
| 1499 |
* @param array $refs |
| 1500 |
* @return array |
| 1501 |
*/ |
| 1502 |
public function insertForm($form, $insertedForms, $formItem) |
| 1503 |
{ |
| 1504 |
$formId = wpFluent()->table('fluentform_forms')->insertGetId($form); |
| 1505 |
$insertedForms[$formId] = [ |
| 1506 |
'title' => $form['title'], |
| 1507 |
'edit_url' => admin_url('admin.php?page=fluent_forms&route=editor&form_id=' . $formId) |
| 1508 |
]; |
| 1509 |
|
| 1510 |
do_action_deprecated( |
| 1511 |
'fluentform_form_imported', |
| 1512 |
[ |
| 1513 |
$formId |
| 1514 |
], |
| 1515 |
FLUENTFORM_FRAMEWORK_UPGRADE, |
| 1516 |
'fluentform/form_imported', |
| 1517 |
'Use fluentform/form_imported instead of fluentform_form_imported.' |
| 1518 |
); |
| 1519 |
do_action('fluentform/form_imported', $formId); |
| 1520 |
|
| 1521 |
return array($insertedForms, $formId); |
| 1522 |
} |
| 1523 |
|
| 1524 |
protected function getFileTypes($field, $arg) |
| 1525 |
{ |
| 1526 |
// All Supported File Types in Fluent Forms |
| 1527 |
$allFileTypes = [ |
| 1528 |
"jpg|jpeg|gif|png|bmp", |
| 1529 |
"mp3|wav|ogg|oga|wma|mka|m4a|ra|mid|midi|mpga", |
| 1530 |
"avi|divx|flv|mov|ogv|mkv|mp4|m4v|divx|mpg|mpeg|mpe|video/quicktime|qt", |
| 1531 |
"pdf", |
| 1532 |
"doc|ppt|pps|xls|mdb|docx|xlsx|pptx|odt|odp|ods|odg|odc|odb|odf|rtf|txt", |
| 1533 |
"zip|gz|gzip|rar|7z", |
| 1534 |
"exe", |
| 1535 |
"csv" |
| 1536 |
]; |
| 1537 |
|
| 1538 |
$formattedTypes = explode(', ', ArrayHelper::get($field, $arg, '')); |
| 1539 |
$fileTypeOptions = []; |
| 1540 |
foreach ($formattedTypes as $format) { |
| 1541 |
foreach ($allFileTypes as $fileTypes) { |
| 1542 |
if (!empty($format) && (strpos($fileTypes, $format) !== false)) { |
| 1543 |
array_push($fileTypeOptions, $fileTypes); |
| 1544 |
} |
| 1545 |
|
| 1546 |
} |
| 1547 |
} |
| 1548 |
|
| 1549 |
return array_unique($fileTypeOptions); |
| 1550 |
} |
| 1551 |
|
| 1552 |
public function isAlreadyImported($formItem) |
| 1553 |
{ |
| 1554 |
$importedFormMap = get_option('__ff_imorted_forms_map'); |
| 1555 |
$deletedForms = []; |
| 1556 |
if (is_array($importedFormMap)) { |
| 1557 |
foreach ($importedFormMap as $fluentFormId => $value) { |
| 1558 |
if ($this->getFormId($formItem) == ArrayHelper::get($value, |
| 1559 |
'imported_form_id') && $this->key == ArrayHelper::get($value, 'form_type')) { |
| 1560 |
|
| 1561 |
if (wpFluent()->table('fluentform_forms')->find($fluentFormId)) { |
| 1562 |
return $fluentFormId; |
| 1563 |
} |
| 1564 |
unset($importedFormMap[$fluentFormId]); |
| 1565 |
|
| 1566 |
} |
| 1567 |
} |
| 1568 |
update_option('__ff_imorted_forms_map', $importedFormMap); |
| 1569 |
return false; |
| 1570 |
} |
| 1571 |
|
| 1572 |
return false; |
| 1573 |
|
| 1574 |
} |
| 1575 |
|
| 1576 |
public function updateForm($formId, $formFields, $insertedForms) |
| 1577 |
{ |
| 1578 |
$data = [ |
| 1579 |
'updated_at' => current_time('mysql'), |
| 1580 |
'form_fields' => $formFields, |
| 1581 |
]; |
| 1582 |
wpFluent()->table('fluentform_forms')->where('id', $formId)->update($data); |
| 1583 |
|
| 1584 |
$form = wpFluent()->table('fluentform_forms')->find($formId); |
| 1585 |
|
| 1586 |
$emailInputs = FormFieldsParser::getElement($form, ['input_email'], ['element', 'attributes']); |
| 1587 |
if ($emailInputs) { |
| 1588 |
$emailInput = array_shift($emailInputs); |
| 1589 |
$emailInputName = ArrayHelper::get($emailInput, 'attributes.name'); |
| 1590 |
(new \FluentForm\App\Modules\Form\Form(wpFluentForm()))->updateMeta($formId, '_primary_email_field', |
| 1591 |
$emailInputName); |
| 1592 |
} else { |
| 1593 |
(new \FluentForm\App\Modules\Form\Form(wpFluentForm()))->updateMeta($formId, '_primary_email_field', ''); |
| 1594 |
} |
| 1595 |
$insertedForms[$formId] = [ |
| 1596 |
'title' => $form->title, |
| 1597 |
'edit_url' => admin_url('admin.php?page=fluent_forms&route=editor&form_id=' . $formId) |
| 1598 |
]; |
| 1599 |
|
| 1600 |
|
| 1601 |
return $insertedForms; |
| 1602 |
|
| 1603 |
} |
| 1604 |
|
| 1605 |
public function insertEntries($fluentFormId, $importFormId) |
| 1606 |
{ |
| 1607 |
if (!wpFluent()->table('fluentform_forms')->find($fluentFormId)) { |
| 1608 |
wp_send_json_error([ |
| 1609 |
'message' => __("Could not find form ,please import again", 'fluentform') |
| 1610 |
], 422); |
| 1611 |
} |
| 1612 |
$entries = $this->getEntries($importFormId); |
| 1613 |
if (!is_array($entries) || empty($entries)) { |
| 1614 |
wp_send_json([ |
| 1615 |
'message' => "No Entries Found", |
| 1616 |
], 200); |
| 1617 |
return; |
| 1618 |
} |
| 1619 |
//delete prev entries |
| 1620 |
$this->resetEntries($fluentFormId); |
| 1621 |
|
| 1622 |
foreach ($entries as $key => $entry) { |
| 1623 |
if (empty($entry)) { |
| 1624 |
continue; |
| 1625 |
} |
| 1626 |
$previousItem = wpFluent()->table('fluentform_submissions') |
| 1627 |
->where('form_id', $fluentFormId) |
| 1628 |
->orderBy('id', 'DESC') |
| 1629 |
->first(); |
| 1630 |
|
| 1631 |
$serialNumber = 1; |
| 1632 |
|
| 1633 |
if ($previousItem) { |
| 1634 |
$serialNumber = $previousItem->serial_number + 1; |
| 1635 |
} |
| 1636 |
$created_at = ArrayHelper::get($entry, 'created_at'); |
| 1637 |
if ($created_at) { |
| 1638 |
ArrayHelper::forget($entry, 'created_at'); |
| 1639 |
} |
| 1640 |
$updated_at = ArrayHelper::get($entry, 'updated_at'); |
| 1641 |
if ($updated_at) { |
| 1642 |
ArrayHelper::forget($entry, 'updated_at'); |
| 1643 |
} |
| 1644 |
$insertData = [ |
| 1645 |
'form_id' => $fluentFormId, |
| 1646 |
'serial_number' => $serialNumber, |
| 1647 |
'response' => json_encode($entry), |
| 1648 |
'source_url' => '', |
| 1649 |
'user_id' => get_current_user_id(), |
| 1650 |
'browser' => '', |
| 1651 |
'device' => '', |
| 1652 |
'ip' => '', |
| 1653 |
'created_at' => $created_at ?: current_time('mysql'), |
| 1654 |
'updated_at' => $updated_at ?: current_time('mysql') |
| 1655 |
]; |
| 1656 |
|
| 1657 |
if ($is_favourite = ArrayHelper::get($entry, 'is_favourite')) { |
| 1658 |
$insertData['is_favourite'] = $is_favourite; |
| 1659 |
ArrayHelper::forget($entry, 'is_favourite'); |
| 1660 |
} |
| 1661 |
if ($status = ArrayHelper::get($entry, 'status')) { |
| 1662 |
$insertData['status'] = $status; |
| 1663 |
ArrayHelper::forget($entry, 'status'); |
| 1664 |
} |
| 1665 |
|
| 1666 |
$insertId = wpFluent()->table('fluentform_submissions')->insertGetId($insertData); |
| 1667 |
|
| 1668 |
$uidHash = md5(wp_generate_uuid4() . $insertId); |
| 1669 |
|
| 1670 |
\FluentForm\App\Helpers\Helper::setSubmissionMeta($insertId, '_entry_uid_hash', $uidHash, $fluentFormId); |
| 1671 |
$submissionService = new SubmissionService(); |
| 1672 |
$submissionService->recordEntryDetails($insertId, $fluentFormId, $entry); |
| 1673 |
} |
| 1674 |
wp_send_json([ |
| 1675 |
'message' => __("Entries Imported Successfully", 'fluentform'), |
| 1676 |
'entries_page_url' => admin_url('admin.php?page=fluent_forms&route=entries&form_id=' . $fluentFormId), |
| 1677 |
'status' => true |
| 1678 |
], 200); |
| 1679 |
|
| 1680 |
} |
| 1681 |
|
| 1682 |
private function resetEntries($formId) |
| 1683 |
{ |
| 1684 |
wpFluent()->table('fluentform_submissions') |
| 1685 |
->where('form_id', $formId) |
| 1686 |
->delete(); |
| 1687 |
|
| 1688 |
wpFluent()->table('fluentform_submission_meta') |
| 1689 |
->where('form_id', $formId) |
| 1690 |
->delete(); |
| 1691 |
|
| 1692 |
wpFluent()->table('fluentform_entry_details') |
| 1693 |
->where('form_id', $formId) |
| 1694 |
->delete(); |
| 1695 |
wpFluent()->table('fluentform_form_analytics') |
| 1696 |
->where('form_id', $formId) |
| 1697 |
->delete(); |
| 1698 |
|
| 1699 |
wpFluent()->table('fluentform_logs') |
| 1700 |
->where('parent_source_id', $formId) |
| 1701 |
->whereIn('source_type', ['submission_item', 'form_item', 'draft_submission_meta']) |
| 1702 |
->delete(); |
| 1703 |
} |
| 1704 |
|
| 1705 |
/** |
| 1706 |
* @param array $urls |
| 1707 |
* |
| 1708 |
* @return array |
| 1709 |
*/ |
| 1710 |
public function migrateFilesAndGetUrls($urls) |
| 1711 |
{ |
| 1712 |
if (is_string($urls)) { |
| 1713 |
$urls = [$urls]; |
| 1714 |
} |
| 1715 |
$values = []; |
| 1716 |
foreach ($urls as $url) { |
| 1717 |
$file_name = 'ff-' . wp_basename($url); |
| 1718 |
$basDir = wp_upload_dir()['basedir'] . '/fluentform/'; |
| 1719 |
$baseurl = wp_upload_dir()['baseurl'] . '/fluentform/'; |
| 1720 |
|
| 1721 |
if (!file_exists($basDir) || (file_exists($basDir) && !is_dir($basDir))) { |
| 1722 |
wp_mkdir_p($basDir); |
| 1723 |
} |
| 1724 |
|
| 1725 |
$destination = $basDir . $file_name; |
| 1726 |
require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php'); |
| 1727 |
require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php'); |
| 1728 |
$fileSystemDirect = new \WP_Filesystem_Direct(false); |
| 1729 |
if ($fileSystemDirect->copy($url, $destination, true)) { |
| 1730 |
$values[] = $baseurl . $file_name; |
| 1731 |
} |
| 1732 |
} |
| 1733 |
return $values; |
| 1734 |
} |
| 1735 |
|
| 1736 |
protected function getResolveOperator($key) |
| 1737 |
{ |
| 1738 |
return ArrayHelper::get([ |
| 1739 |
'equal' => '=', |
| 1740 |
'is' => '=', |
| 1741 |
'==' => '=', |
| 1742 |
'e' => '=', |
| 1743 |
'not_equal' => '!=', |
| 1744 |
'isnot' => '!=', |
| 1745 |
'!=' => '!=', |
| 1746 |
'!e' => '!=', |
| 1747 |
'greater_than' => '>', |
| 1748 |
'>' => '>', |
| 1749 |
'greater_or_equal' => '>=', |
| 1750 |
'>=' => '>=', |
| 1751 |
'less_than' => '<', |
| 1752 |
'<' => '<', |
| 1753 |
'less_or_equal' => '<=', |
| 1754 |
'<=' => '<=', |
| 1755 |
'starts_with' => 'startsWith', |
| 1756 |
'^' => 'startsWith', |
| 1757 |
'ends_with' => 'endsWith', |
| 1758 |
'~' => 'endsWith', |
| 1759 |
'contains' => 'contains', |
| 1760 |
'c' => 'contains', |
| 1761 |
'!c' => 'doNotContains', |
| 1762 |
'not_contains' => 'doNotContains' |
| 1763 |
], $key); |
| 1764 |
} |
| 1765 |
|
| 1766 |
} |
| 1767 |
|