customs
5 months ago
holders
5 months ago
checkbox.php
5 months ago
color-and-opacity.php
5 months ago
color.php
5 months ago
datepicker-range.php
5 months ago
dropdown-and-colors.php
5 months ago
dropdown.php
5 months ago
font.php
5 months ago
google-font.php
5 months ago
gradient.php
5 months ago
hidden.php
5 months ago
index.php
5 months ago
integer.php
5 months ago
list.php
5 months ago
multiple-textbox.php
5 months ago
paddings-editor.php
5 months ago
pattern.php
5 months ago
radio-colors.php
5 months ago
radio.php
5 months ago
textarea.php
5 months ago
textbox.php
5 months ago
url.php
5 months ago
wp-editor.php
5 months ago
multiple-textbox.php
115 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Control multiple textbox |
| 5 | * |
| 6 | * @package factory-forms |
| 7 | * @since 1.0.0 |
| 8 | */ |
| 9 | |
| 10 | // Exit if accessed directly |
| 11 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | exit; |
| 13 | } |
| 14 | |
| 15 | if ( ! class_exists( 'Wbcr_FactoryForms600_MultipleTextboxControl' ) ) { |
| 16 | |
| 17 | class Wbcr_FactoryForms600_MultipleTextboxControl extends Wbcr_FactoryForms600_Control { |
| 18 | |
| 19 | public $type = 'multiple-textbox'; |
| 20 | |
| 21 | /** |
| 22 | * Preparing html attributes before rendering html of the control. |
| 23 | * |
| 24 | * @since 1.0.0 |
| 25 | * @return void |
| 26 | */ |
| 27 | protected function beforeHtml() { |
| 28 | |
| 29 | $name_on_form = $this->getNameOnForm(); |
| 30 | |
| 31 | if ( $this->getOption( 'maxLength', false ) ) { |
| 32 | $this->addHtmlAttr( 'maxlength', intval( $this->getOption( 'maxLength' ) ) ); |
| 33 | } |
| 34 | |
| 35 | if ( $this->getOption( 'placeholder', false ) ) { |
| 36 | $this->addHtmlAttr( 'placeholder', $this->getOption( 'placeholder' ) ); |
| 37 | } |
| 38 | |
| 39 | $this->addCssClass( 'form-control' ); |
| 40 | $this->addHtmlAttr( 'type', 'text' ); |
| 41 | // $this->addHtmlAttr('id', $name_on_form); |
| 42 | $this->addCssClass( str_replace( '_', '-', $name_on_form ) ); |
| 43 | $this->addHtmlAttr( 'name', $name_on_form . '[]' ); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Shows the html markup of the control. |
| 48 | * |
| 49 | * @since 1.0.0 |
| 50 | * @return void |
| 51 | */ |
| 52 | public function html() { |
| 53 | |
| 54 | $values = $this->getValue(); |
| 55 | |
| 56 | if ( ! empty( $values ) ) { |
| 57 | $values = explode( '{%spr%}', $values ); |
| 58 | } else { |
| 59 | $values = []; |
| 60 | } |
| 61 | |
| 62 | ?> |
| 63 | <div class="factory-multiple-textbox-group"> |
| 64 | <div class="factory-mtextbox-items"> |
| 65 | <?php if ( empty( $values ) ) : ?> |
| 66 | <div class="factory-mtextbox-item"> |
| 67 | <input <?php $this->attrs(); ?>/> |
| 68 | </div> |
| 69 | <?php else : ?> |
| 70 | <?php $counter = 0; ?> |
| 71 | <?php foreach ( $values as $value ) : ?> |
| 72 | <div class="factory-mtextbox-item"> |
| 73 | <input value="<?php echo esc_attr( $value ); ?>"<?php $this->attrs(); ?>/> |
| 74 | <?php if ( $counter >= 1 ) : ?> |
| 75 | <button class="btn btn-default btn-small factory-mtextbox-remove-item"> |
| 76 | <i class="fa fa-times" aria-hidden="true"></i></button> |
| 77 | <?php endif; ?> |
| 78 | </div> |
| 79 | <?php ++$counter; ?> |
| 80 | <?php endforeach; ?> |
| 81 | <?php endif; ?> |
| 82 | </div> |
| 83 | <button class="btn btn-default btn-small factory-mtextbox-add-item"> |
| 84 | <i class="fa fa-plus" aria-hidden="true"></i> <?php _e( 'Add new', 'robin-image-optimizer' ); ?> |
| 85 | </button> |
| 86 | </div> |
| 87 | |
| 88 | <?php |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Returns a submit value of the control by a given name. |
| 93 | * |
| 94 | * @since 1.0.0 |
| 95 | * @return mixed |
| 96 | */ |
| 97 | public function getSubmitValue( $name, $subName ) { |
| 98 | $name_on_form = $this->getNameOnForm( $name ); |
| 99 | |
| 100 | $value = isset( $_POST[ $name_on_form ] ) |
| 101 | ? $_POST[ $name_on_form ] |
| 102 | : null; |
| 103 | |
| 104 | if ( is_array( $value ) ) { |
| 105 | $value = array_map( 'sanitize_text_field', $value ); |
| 106 | $value = implode( '{%spr%}', $value ); |
| 107 | } |
| 108 | |
| 109 | $value = sanitize_text_field( $value ); |
| 110 | |
| 111 | return $value; |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 |