Overview

Namespaces

  • None
  • Quform
    • Traduttore_Registry

Classes

  • Quform
  • Quform_Admin_InsertForm
  • Quform_Admin_Page
  • Quform_Admin_Page_Controller
  • Quform_Admin_Page_Dashboard
  • Quform_Admin_Page_Entries
  • Quform_Admin_Page_Entries_Edit
  • Quform_Admin_Page_Entries_List
  • Quform_Admin_Page_Entries_View
  • Quform_Admin_Page_Factory
  • Quform_Admin_Page_Forms_Add
  • Quform_Admin_Page_Forms_Edit
  • Quform_Admin_Page_Forms_List
  • Quform_Admin_Page_Help
  • Quform_Admin_Page_Preview
  • Quform_Admin_Page_Settings
  • Quform_Admin_Page_Tools
  • Quform_Admin_Page_Tools_ExportEntries
  • Quform_Admin_Page_Tools_ExportForm
  • Quform_Admin_Page_Tools_Home
  • Quform_Admin_Page_Tools_ImportForm
  • Quform_Admin_Page_Tools_Migrate
  • Quform_Admin_Page_Tools_Uninstall
  • Quform_Api
  • Quform_Block
  • Quform_Builder
  • Quform_Captcha
  • Quform_ClassLoader
  • Quform_Confirmation
  • Quform_Container
  • Quform_Dashboard_Widget
  • Quform_Dispatcher
  • Quform_Element
  • Quform_Element_Captcha
  • Quform_Element_Checkbox
  • Quform_Element_Column
  • Quform_Element_Container
  • Quform_Element_Container_Iterator
  • Quform_Element_Date
  • Quform_Element_Email
  • Quform_Element_Factory
  • Quform_Element_Field
  • Quform_Element_File
  • Quform_Element_Group
  • Quform_Element_Hidden
  • Quform_Element_Honeypot
  • Quform_Element_Html
  • Quform_Element_Multi
  • Quform_Element_Multiselect
  • Quform_Element_Name
  • Quform_Element_Page
  • Quform_Element_Password
  • Quform_Element_Radio
  • Quform_Element_Recaptcha
  • Quform_Element_Row
  • Quform_Element_Select
  • Quform_Element_Submit
  • Quform_Element_Text
  • Quform_Element_Textarea
  • Quform_Element_Time
  • Quform_Entry_Controller
  • Quform_Entry_Exporter
  • Quform_Entry_List_Settings
  • Quform_Entry_List_Table
  • Quform_Entry_Processor
  • Quform_Entry_UserSearcher
  • Quform_Filter_Abstract
  • Quform_Filter_Alpha
  • Quform_Filter_AlphaNumeric
  • Quform_Filter_Digits
  • Quform_Filter_Regex
  • Quform_Filter_Static
  • Quform_Filter_StripTags
  • Quform_Filter_Trim
  • Quform_Form
  • Quform_Form_Controller
  • Quform_Form_Exporter
  • Quform_Form_Factory
  • Quform_Form_Importer
  • Quform_Form_Iterator
  • Quform_Form_List_Settings
  • Quform_Form_List_Table
  • Quform_Form_Processor
  • Quform_License
  • Quform_Migrator
  • Quform_NonceRefresher
  • Quform_Notification
  • Quform_Notification_Resender
  • Quform_Options
  • Quform_Permissions
  • Quform_Repository
  • Quform_ScriptLoader
  • Quform_Session
  • Quform_Settings
  • Quform_Shortcode
  • Quform_Themes
  • Quform_TokenReplacer
  • Quform_Toolbar
  • Quform_Translations
  • Quform_Updater
  • Quform_Upgrader
  • Quform_Uploader
  • Quform_Validator_Abstract
  • Quform_Validator_Alpha
  • Quform_Validator_AlphaNumeric
  • Quform_Validator_Array
  • Quform_Validator_Captcha
  • Quform_Validator_Date
  • Quform_Validator_Digits
  • Quform_Validator_Duplicate
  • Quform_Validator_Email
  • Quform_Validator_FileUpload
  • Quform_Validator_GreaterThan
  • Quform_Validator_Honeypot
  • Quform_Validator_Identical
  • Quform_Validator_InArray
  • Quform_Validator_Length
  • Quform_Validator_LessThan
  • Quform_Validator_Recaptcha
  • Quform_Validator_Regex
  • Quform_Validator_Required
  • Quform_Validator_Static
  • Quform_Validator_Time
  • Quform_View
  • Quform_ViewFactory
  • Quform_Widget_Form
  • Quform_Widget_Popup

Interfaces

  • Quform_Attachable
  • Quform_Element_Editable
  • Quform_Filter_Interface
  • Quform_Validator_Interface

Constants

  • Quform\Traduttore_Registry\TRANSIENT_KEY_PLUGIN
  • Quform\Traduttore_Registry\TRANSIENT_KEY_THEME

Functions

  • Quform\Traduttore_Registry\add_project
  • Quform\Traduttore_Registry\clean_translations_cache
  • Quform\Traduttore_Registry\get_available_locales
  • Quform\Traduttore_Registry\get_installed_translations
  • Quform\Traduttore_Registry\get_translations
  • Quform\Traduttore_Registry\register_clean_translations_cache
  • Quform\Traduttore_Registry\sanitize_date
  • Overview
  • Namespace
  • Class
  1: <?php
  2: 
  3: /**
  4:  * @copyright Copyright (c) 2009-2022 ThemeCatcher (https://www.themecatcher.net)
  5:  */
  6: class Quform_Element_Name extends Quform_Element_Field implements Quform_Element_Editable
  7: {
  8:     /**
  9:      * @var array
 10:      */
 11:     static $partKeys = array(
 12:         1 => 'prefix',
 13:         2 => 'first',
 14:         3 => 'middle',
 15:         4 => 'last',
 16:         5 => 'suffix'
 17:     );
 18: 
 19:     /**
 20:      * @var Quform_Element_Field[]
 21:      */
 22:     protected $parts = array();
 23: 
 24:     /**
 25:      * @var array
 26:      */
 27:     protected $value = array();
 28: 
 29:     /**
 30:      * Set the value
 31:      *
 32:      * @param mixed $value
 33:      */
 34:     public function setValue($value)
 35:     {
 36:         parent::setValue($value);
 37: 
 38:         $value = $this->getValue();
 39: 
 40:         foreach (self::$partKeys as $key => $slug) {
 41:             if (array_key_exists($key, $this->parts) && array_key_exists($key, $value)) {
 42:                 $this->parts[$key]->setValue($value[$key]);
 43:             }
 44:         }
 45:     }
 46: 
 47:     /**
 48:      * Get the filtered value
 49:      *
 50:      * @return array The filtered value
 51:      */
 52:     public function getValue()
 53:     {
 54:         $value = $this->value;
 55: 
 56:         $this->filterValueRecursive($value);
 57: 
 58:         $value = apply_filters('quform_get_value_' . $this->getIdentifier(), $value, $this, $this->getForm());
 59: 
 60:         return $value;
 61:     }
 62: 
 63:     /**
 64:      * Get the value formatted in HTML
 65:      *
 66:      * @return string
 67:      */
 68:     public function getValueHtml()
 69:     {
 70:         $value = Quform::escape($this->getValueText());
 71: 
 72:         $value = apply_filters('quform_get_value_html_' . $this->getIdentifier(), $value, $this, $this->getForm());
 73: 
 74:         return $value;
 75:     }
 76: 
 77:     /**
 78:      * Get the value formatted in plain text
 79:      *
 80:      * @param   string  $separator  The separator for array types (not used here)
 81:      * @return  string
 82:      */
 83:     public function getValueText($separator = ', ')
 84:     {
 85:         $nonEmptyParts = array();
 86: 
 87:         foreach ($this->getValue() as $value) {
 88:             if (Quform::isNonEmptyString($value)) {
 89:                 $nonEmptyParts[] = $value;
 90:             }
 91:         }
 92: 
 93:         $value = join(' ', $nonEmptyParts);
 94: 
 95:         $value = apply_filters('quform_get_value_text_' . $this->getIdentifier(), $value, $this, $this->getForm());
 96: 
 97:         return $value;
 98:     }
 99: 
100:     /**
101:      * Is the given value valid for this element type
102:      *
103:      * @param   array  $value
104:      * @return  bool
105:      */
106:     protected function isValidValue($value)
107:     {
108:         if ( ! is_array($value)) {
109:             return false;
110:         }
111: 
112:         foreach ($value as $key => $val) {
113:             if ( ! array_key_exists($key, self::$partKeys) || ! parent::isValidValue($val)) {
114:                 return false;
115:             }
116:         }
117: 
118:         return true;
119:     }
120: 
121:     /**
122:      * Does this element have the given value?
123:      *
124:      * @param   mixed    $value
125:      * @return  boolean
126:      */
127:     public function hasValue($value)
128:     {
129:         return $this->getValueText() === $value;
130:     }
131: 
132:     /**
133:      * @return array
134:      */
135:     public function getEmptyValue()
136:     {
137:         return array();
138:     }
139: 
140:     /**
141:      * Get the value in storage format
142:      *
143:      * @return string
144:      */
145:     protected function getConvertedValueForStorage()
146:     {
147:         return serialize($this->getValue());
148:     }
149: 
150:     /**
151:      * Convert given the value from storage format
152:      *
153:      * @param   string  $value
154:      * @return  array
155:      */
156:     protected function convertValueFromStorage($value)
157:     {
158:         return is_serialized($value) ? unserialize($value) : $this->getEmptyValue();
159:     }
160: 
161:     /**
162:      * @return bool
163:      */
164:     public function isRequired()
165:     {
166:         $required = false;
167: 
168:         foreach ($this->parts as $part) {
169:             if ($part->isRequired()) {
170:                 $required = true;
171:             }
172:         }
173: 
174:         return $required;
175:     }
176: 
177:     /**
178:      * If the value is not an array or is an empty array it's empty
179:      *
180:      * @return bool
181:      */
182:     public function isEmpty()
183:     {
184:         return $this->hasValue('');
185:     }
186: 
187:     /**
188:      * Set a part by name
189:      *
190:      * @param  $name
191:      * @param  Quform_Element_Field  $element
192:      */
193:     public function setPart($name, Quform_Element_Field $element)
194:     {
195:         $this->parts[$name] = $element;
196:     }
197: 
198:     /**
199:      * Get a part by name
200:      *
201:      * @param   string  $name  The name of the part
202:      * @return  Quform_Element_Field|null
203:      */
204:     public function getPart($name)
205:     {
206:         return isset($this->parts[$name]) ? $this->parts[$name] : null;
207:     }
208: 
209:     /**
210:      * Is this element valid?
211:      *
212:      * @return bool
213:      */
214:     public function isValid()
215:     {
216:         $this->clearErrors();
217:         $skipValidation = false;
218:         $valid = true;
219: 
220:         // Skip validation if the element is conditionally hidden, or not visible (e.g. admin only)
221:         if ($this->isConditionallyHidden() || ! $this->isVisible()) {
222:             $skipValidation = true;
223:         }
224: 
225:         if ( ! $skipValidation) {
226:             $value = $this->getValue();
227: 
228:             foreach ($this->parts as $part) {
229:                 if ( ! $part->isValid()) {
230:                     $valid = false;
231:                 }
232:             }
233: 
234:             foreach ($this->getValidators() as $validator) {
235:                 if ($validator->isValid($value)) {
236:                     continue;
237:                 }
238: 
239:                 $this->addError($validator->getMessage());
240:                 $valid = false;
241:                 break;
242:             }
243: 
244:             $valid = apply_filters('quform_element_valid', $valid, $value, $this);
245:             $valid = apply_filters('quform_element_valid_' . $this->getIdentifier(), $valid, $value, $this);
246:         }
247: 
248:         return $valid;
249:     }
250: 
251:     /**
252:      * @return bool
253:      */
254:     public function hasError()
255:     {
256:         $hasError = false;
257: 
258:         if (parent::hasError()) {
259:             $hasError = true;
260:         }
261: 
262:         foreach ($this->parts as $part) {
263:             if ($part->hasError()) {
264:                 $hasError = true;
265:             }
266:         }
267: 
268:         return $hasError;
269:     }
270: 
271:     /**
272:      * @return array
273:      */
274:     public function getErrorArray()
275:     {
276:         $errors = array();
277: 
278:         if (parent::hasError()) {
279:             $errors[$this->getIdentifier()] = $this->getError();
280:         }
281: 
282:         foreach ($this->parts as $part) {
283:             if ($part->hasError()) {
284:                 $errors[$part->getIdentifier()] = $part->getError();
285:             }
286:         }
287: 
288:         return $errors;
289:     }
290: 
291:     /**
292:      * Get the HTML for the element label
293:      *
294:      * @param   array        $context
295:      * @param   string|bool  $forAttribute  Set the "for" attribute to the element unique ID
296:      * @param   bool         $id            Add a unique ID to the label
297:      * @return  string
298:      */
299:     protected function getLabelHtml(array $context = array(), $forAttribute = true, $id = false)
300:     {
301:         return parent::getLabelHtml($context, false, true);
302:     }
303: 
304:     /**
305:      * Get the HTML for the element input wrapper
306:      *
307:      * @param   array   $context
308:      * @return  string
309:      */
310:     protected function getInputHtml(array $context = array())
311:     {
312:         $output = sprintf('<div class="%s">', Quform::escape(Quform::sanitizeClass($this->getInputClasses($context))));
313: 
314:         $rowClasses = array(
315:             'quform-element-row',
316:             sprintf('quform-%d-columns', count($this->parts)),
317:             Quform::isNonEmptyString($context['fieldWidth']) ? 'quform-element-row-size-float' : 'quform-element-row-size-fixed', // For non-100% input widths use float class
318:         );
319: 
320:         if (Quform::isNonEmptyString($context['responsiveColumns']) && $context['responsiveColumns'] != 'custom') {
321:             $rowClasses[] = sprintf('quform-responsive-columns-%s', $context['responsiveColumns']);
322:         }
323: 
324:         $output .= sprintf('<div class="%s">', Quform::escape(Quform::sanitizeClass($rowClasses)));
325: 
326:         $output .= $this->getFieldHtml($context);
327: 
328:         $output .= '</div>';
329: 
330:         $output .= '</div>';
331: 
332:         return $output;
333:     }
334: 
335:     /**
336:      * Get the HTML for the field
337:      *
338:      * @param   array   $context
339:      * @return  string
340:      */
341:     protected function getFieldHtml(array $context = array())
342:     {
343:         $output = '';
344: 
345:         foreach (self::$partKeys as $key => $slug) {
346:             if ($this->config($slug . 'Enabled') && ($part = $this->getPart($key)) instanceof Quform_Element) {
347:                 $ariaLabelledby = array();
348: 
349:                 if (Quform::isNonEmptyString($this->getLabel($context))) {
350:                     $ariaLabelledby[] = $this->getUniqueId() . '_label';
351:                 }
352: 
353:                 if (Quform::isNonEmptyString($part->config('subLabelAbove'))) {
354:                     $ariaLabelledby[] = $part->getUniqueId() . '_sub_label_above';
355:                 }
356: 
357:                 if (Quform::isNonEmptyString($part->config('subLabel'))) {
358:                     $ariaLabelledby[] = $part->getUniqueId() . '_sub_label_below';
359:                 }
360: 
361:                 if (count($ariaLabelledby)) {
362:                     $part->setConfig('aria-labelledby', join(' ', $ariaLabelledby));
363:                 }
364: 
365:                 $output .= sprintf('<div class="quform-element-column">%s</div>', $part->render($context));
366:             }
367:         }
368: 
369:         return $output;
370:     }
371: 
372:     /**
373:      * Get the field HTML when editing
374:      *
375:      * @return string
376:      */
377:     public function getEditFieldHtml()
378:     {
379:         $output = sprintf('<div class="qfb-edit-name-row qfb-edit-name-row-%d">', count($this->parts));
380: 
381:         foreach (self::$partKeys as $key => $slug) {
382:             if ($this->config($slug . 'Enabled') && $this->getPart($key) instanceof Quform_Element_Editable) {
383:                 $part = $this->getPart($key);
384: 
385:                 $output .= sprintf(
386:                     '<div class="qfb-edit-name-column"><div class="qfb-edit-element qfb-edit-element-%1$s"><div class="qfb-edit-input qfb-edit-input-%1$s">%2$s</div></div></div>',
387:                     $part->getIdentifier(),
388:                     $part->getEditFieldHtml()
389:                 );
390:             }
391:         }
392: 
393:         $output .= '</div>';
394: 
395:         return $output;
396:     }
397: 
398:     /**
399:      * Render the CSS for this field
400:      *
401:      * @param   array   $context
402:      * @return  string
403:      */
404:     protected function renderCss(array $context = array())
405:     {
406:         $css = parent::renderCss($context);
407: 
408:         if ($context['fieldWidth'] == 'custom' && Quform::isNonEmptyString($context['fieldWidthCustom'])) {
409:             $css .= sprintf('.quform-input-name.quform-input-%s { width: %s; }', $this->getIdentifier(), Quform::addCssUnit($context['fieldWidthCustom']));
410:             $css .= sprintf('.quform-input-name.quform-input-%s .quform-inner > .quform-input { width: 100%% !important; }', $this->getIdentifier(), Quform::addCssUnit($context['fieldWidthCustom']));
411:             $css .= sprintf('.quform-inner-%s > .quform-error > .quform-error-inner { float: left; min-width: %s; }', $this->getIdentifier(), Quform::addCssUnit($context['fieldWidthCustom']));
412:         }
413: 
414:         if ($context['responsiveColumns'] == 'custom' && Quform::isNonEmptyString($context['responsiveColumnsCustom'])) {
415:             $css .= sprintf(
416:                 '@media (max-width: %s) { .quform-input-%s > .quform-element-row > .quform-element-column { float: none; width: 100%% !important; } }',
417:                 Quform::addCssUnit($context['responsiveColumnsCustom']),
418:                 $this->getIdentifier()
419:             );
420:         }
421: 
422:         foreach ($this->parts as $part) {
423:             $css .= $part->getCss($context);
424:         }
425: 
426:         return $css;
427:     }
428: 
429:     /**
430:      * Inherit settings from this element into the context
431:      *
432:      * @param   array  $context
433:      * @return  array
434:      */
435:     protected function prepareContext(array $context = array())
436:     {
437:         $context = parent::prepareContext($context);
438: 
439:         // Inside labels are not possible so set it above
440:         if ( ! in_array($context['labelPosition'], array('', 'left'), true)) {
441:             $context['labelPosition'] = '';
442:         }
443: 
444:         // Icon is the only possible tooltip type for this element
445:         $context['tooltipType'] = 'icon';
446: 
447:         if (is_string($this->config('responsiveColumns'))) {
448:             if ($this->config('responsiveColumns') != 'inherit') {
449:                 $context['responsiveColumns'] = $this->config('responsiveColumns');
450: 
451:                 if ($this->config('responsiveColumns') == 'custom' && Quform::isNonEmptyString($this->config('responsiveColumnsCustom'))) {
452:                     $context['responsiveColumnsCustom'] = $this->config('responsiveColumnsCustom');
453:                 }
454:             }
455:         }
456: 
457:         return $context;
458:     }
459: 
460:     /**
461:      * Get the default element configuration
462:      *
463:      * @param   string|null  $key  Get the config by key, if omitted the full config is returned
464:      * @return  array
465:      */
466:     public static function getDefaultConfig($key = null)
467:     {
468:         $config = apply_filters('quform_default_config_name', array(
469:             // Basic
470:             'label' => __('Name', 'quform'),
471:             'description' => '',
472:             'descriptionAbove' => '',
473:             'prefixEnabled' => false,
474:             'prefixRequired' => false,
475:             'prefixOptions' => array(
476:                 array('id' => 1, 'label' => __('Mr', 'quform'), 'value' => __('Mr', 'quform')),
477:                 array('id' => 2, 'label' => __('Mrs', 'quform'), 'value' => __('Mrs', 'quform')),
478:                 array('id' => 3, 'label' => __('Ms', 'quform'), 'value' => __('Ms', 'quform')),
479:                 array('id' => 4, 'label' => __('Miss', 'quform'), 'value' => __('Miss', 'quform')),
480:                 array('id' => 5, 'label' => __('Dr', 'quform'), 'value' => __('Dr', 'quform')),
481:             ),
482:             'prefixNextOptionId' => 6,
483:             'prefixDefaultValue' => '',
484:             'prefixCustomiseValues' => false,
485:             'prefixNoneOption' => true,
486:             'prefixSubLabel' => __('Prefix', 'quform'),
487:             'prefixSubLabelAbove' => '',
488:             'prefixCustomClass' => '',
489:             'prefixCustomElementClass' => '',
490:             'firstEnabled' => true,
491:             'firstRequired' => false,
492:             'firstPlaceholder' => '',
493:             'firstSubLabel' => __('First', 'quform'),
494:             'firstSubLabelAbove' => '',
495:             'firstDefaultValue' => '',
496:             'firstCustomClass' => '',
497:             'firstCustomElementClass' => '',
498:             'firstAutocomplete' => '',
499:             'middleEnabled' => false,
500:             'middleRequired' => false,
501:             'middlePlaceholder' => '',
502:             'middleSubLabel' => __('Middle', 'quform'),
503:             'middleSubLabelAbove' => '',
504:             'middleDefaultValue' => '',
505:             'middleCustomClass' => '',
506:             'middleCustomElementClass' => '',
507:             'middleAutocomplete' => '',
508:             'lastEnabled' => true,
509:             'lastRequired' => false,
510:             'lastPlaceholder' => '',
511:             'lastSubLabel' => __('Last', 'quform'),
512:             'lastSubLabelAbove' => '',
513:             'lastDefaultValue' => '',
514:             'lastCustomClass' => '',
515:             'lastCustomElementClass' => '',
516:             'lastAutocomplete' => '',
517:             'suffixEnabled' => false,
518:             'suffixRequired' => false,
519:             'suffixPlaceholder' => '',
520:             'suffixSubLabel' => __('Suffix', 'quform'),
521:             'suffixSubLabelAbove' => '',
522:             'suffixDefaultValue' => '',
523:             'suffixCustomClass' => '',
524:             'suffixCustomElementClass' => '',
525: 
526:             // Styles
527:             'labelIcon' => '',
528:             'fieldSize' => 'inherit',
529:             'fieldWidth' => 'inherit',
530:             'fieldWidthCustom' => '',
531:             'responsiveColumns' => 'inherit',
532:             'responsiveColumnsCustom' => '',
533:             'customClass' => '',
534:             'customElementClass' => '',
535:             'styles' => array(),
536: 
537:             // Labels
538:             'subLabel' => '',
539:             'subLabelAbove' => '',
540:             'adminLabel' => '',
541:             'tooltip' => '',
542:             'tooltipType' => 'icon',
543:             'tooltipEvent' => 'inherit',
544:             'labelPosition' => 'inherit',
545:             'labelWidth' => '',
546: 
547:             // Logic
548:             'logicEnabled' => false,
549:             'logicAction' => true,
550:             'logicMatch' => 'all',
551:             'logicRules' => array(),
552: 
553:             // Data
554:             'dynamicDefaultValue' => false,
555:             'dynamicKey' => '',
556:             'showInEmail' => true,
557:             'saveToDatabase' => true,
558: 
559:             // Advanced
560:             'visibility' => '',
561:             'validators' => array(),
562: 
563:             // Translations
564:             'prefixNoneOptionText' => '',
565:             'messageRequired' => ''
566:         ));
567: 
568:         $config['type'] = 'name';
569: 
570:         if (Quform::isNonEmptyString($key)) {
571:             return Quform::get($config, $key);
572:         }
573: 
574:         return $config;
575:     }
576: }
577: 
API documentation generated by ApiGen