PluginProbe
Disable Comments & Delete All Comments / trunk
Disable Comments & Delete All Comments vtrunk
1.3.3 1.3.2 trunk 1.0.0 1.0.4 1.0.5 1.0.8 1.0.9 1.1.1 1.1.3 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.3.0 1.3.1
comments-plus / libs / factory / forms / controls / multiple-textbox.php

multiple-textbox.php in Disable Comments & Delete All Comments trunk, at libs/factory/forms/controls/multiple-textbox.php

121 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Control multiple textbox
5 *
6 * @author Alex Kovalev <alex.kovalevv@gmail.com>
7 * @copyright (c) 2018, Webcraftic Ltd
8 *
9 * @package factory-forms
10 * @since 1.0.0
11 */
12
13 // Exit if accessed directly
14 if( !defined('ABSPATH') ) {
15 exit;
16 }
17
18 if( !class_exists('Wbcr_FactoryForms480_MultipleTextboxControl') ) {
19
20 class Wbcr_FactoryForms480_MultipleTextboxControl extends Wbcr_FactoryForms480_Control {
21
22 public $type = 'multiple-textbox';
23
24 /**
25 * Preparing html attributes before rendering html of the control.
26 *
27 * @since 1.0.0
28 * @return void
29 */
30 protected function beforeHtml()
31 {
32
33 $name_on_form = $this->getNameOnForm();
34
35 if( $this->getOption('maxLength', false) ) {
36 $this->addHtmlAttr('maxlength', intval($this->getOption('maxLength')));
37 }
38
39 if( $this->getOption('placeholder', false) ) {
40 $this->addHtmlAttr('placeholder', $this->getOption('placeholder'));
41 }
42
43 $this->addCssClass('form-control');
44 $this->addHtmlAttr('type', 'text');
45 //$this->addHtmlAttr('id', $name_on_form);
46 $this->addCssClass(str_replace('_', '-', $name_on_form));
47 $this->addHtmlAttr('name', $name_on_form . '[]');
48 }
49
50 /**
51 * Shows the html markup of the control.
52 *
53 * @since 1.0.0
54 * @return void
55 */
56 public function html()
57 {
58
59 $values = $this->getValue();
60
61 if( !empty($values) ) {
62 $values = explode('{%spr%}', $values);
63 } else {
64 $values = array();
65 }
66
67 ?>
68 <div class="factory-multiple-textbox-group">
69 <div class="factory-mtextbox-items">
70 <?php if( empty($values) ): ?>
71 <div class="factory-mtextbox-item">
72 <input <?php $this->attrs() ?>/>
73 </div>
74 <?php else: ?>
75 <?php $counter = 0; ?>
76 <?php foreach($values as $value): ?>
77 <div class="factory-mtextbox-item">
78 <input value="<?php echo esc_attr($value) ?>"<?php $this->attrs() ?>/>
79 <?php if( $counter >= 1 ): ?>
80 <button class="btn btn-default btn-small factory-mtextbox-remove-item">
81 <i class="fa fa-times" aria-hidden="true"></i></button>
82 <?php endif; ?>
83 </div>
84 <?php $counter++; ?>
85 <?php endforeach; ?>
86 <?php endif; ?>
87 </div>
88 <button class="btn btn-default btn-small factory-mtextbox-add-item">
89 <i class="fa fa-plus" aria-hidden="true"></i> <?php _e('Add new', 'wbcr_factory_forms_480') ?>
90 </button>
91 </div>
92
93 <?php
94 }
95
96 /**
97 * Returns a submit value of the control by a given name.
98 *
99 * @since 1.0.0
100 * @return mixed
101 */
102 public function getSubmitValue($name, $subName)
103 {
104 $name_on_form = $this->getNameOnForm($name);
105
106 $value = isset($_POST[$name_on_form])
107 ? $_POST[$name_on_form]
108 : null;
109
110 if( is_array($value) ) {
111 $value = array_map('sanitize_text_field', $value);
112 $value = implode('{%spr%}', $value);
113 }
114
115 $value = sanitize_text_field($value);
116
117 return $value;
118 }
119 }
120 }
121