PluginProbe
Hash Form – Drag & Drop Form Builder / trunk
Hash Form – Drag & Drop Form Builder vtrunk
1.4.4 1.4.3 1.4.2 1.4.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.6.1 1.2.7 1.2.8 1.2.9 1.3.0 All 47 releases
hash-form / includes / fields / HashFormFieldText.php

HashFormFieldText.php in Hash Form – Drag & Drop Form Builder trunk, at includes/fields/HashFormFieldText.php

52 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined('ABSPATH') || die();
3
4 class HashFormFieldText extends HashFormFieldType {
5
6 protected $type = 'text';
7
8 protected function field_settings_for_type() {
9 return array(
10 'advanced_validation' => true,
11 'clear_on_focus' => true,
12 'invalid' => true,
13 'format' => true,
14 'max' => true
15 );
16 }
17
18 public function validate($args) {
19 $errors = array();
20
21 $format = trim((string) HashFormFields::get_option($this->field, 'format'));
22 $max_length = intval(HashFormFields::get_option($this->field, 'max'));
23
24 // Only run the format check when one is configured and a value was
25 // submitted — an empty optional field must not fail the pattern.
26 if ($format !== '' && $args['value'] !== '' && !preg_match(self::format($this->field), $args['value'])) {
27 $errors['field' . $args['id']] = apply_filters('hashform_translate_string', HashFormFields::get_error_msg($this->field, 'invalid'), 'Hash Form', HashFormBuilder::get_form_title($args['form_id']) . ' - ' . $args['id'] . ' - ' . 'Field Validation Message');
28 }
29
30 if ($max_length && strlen($args['value']) > $max_length) {
31 $errors['field' . $args['id']] = HashFormFields::get_error_msg($this->field, 'max_char');
32 }
33 return $errors;
34 }
35
36 public static function format($field) {
37 $pattern = HashFormFields::get_option($field, 'format');
38 // Escape raw delimiters so an admin pattern containing "/" cannot
39 // break the expression (preg_match would then always fail). Already
40 // escaped slashes are normalized first to avoid double escaping.
41 $pattern = str_replace('\/', '/', $pattern);
42 return '/' . str_replace('/', '\/', $pattern) . '/';
43 }
44
45 protected function input_html() {
46 ?>
47 <input type="text" <?php $this->field_attrs(); ?> />
48 <?php
49 }
50
51 }
52