PluginProbe ʕ •ᴥ•ʔ
Disable Admin Notices – Hide Dashboard Notifications / trunk
Disable Admin Notices – Hide Dashboard Notifications vtrunk
1.4.5 trunk 1.0.0 1.0.2 1.0.3 1.0.5 1.0.6 1.1.1 1.1.3 1.1.4 1.2.0 1.2.2 1.2.3 1.2.4 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4
disable-admin-notices / libs / factory / forms / controls / multiple-textbox.php
disable-admin-notices / libs / factory / forms / controls Last commit date
customs 1 year ago holders 1 year ago checkbox.php 1 year ago color-and-opacity.php 1 year ago color.php 1 year ago datepicker-range.php 1 year ago dropdown-and-colors.php 1 year ago dropdown.php 1 year ago font.php 1 year ago google-font.php 1 year ago gradient.php 1 year ago hidden.php 1 year ago index.php 3 years ago integer.php 1 year ago list.php 1 year ago multiple-textbox.php 1 year ago paddings-editor.php 1 year ago pattern.php 1 year ago radio-colors.php 1 year ago radio.php 1 year ago textarea.php 1 year ago textbox.php 1 year ago url.php 1 year ago wp-editor.php 1 year ago
multiple-textbox.php
121 lines
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