1: <?php
2: /**
3: * This file is part of the PHPLucidFrame library.
4: * Core utility for AJAX form handling and form validation
5: *
6: * @package PHPLucidFrame\Core
7: * @since PHPLucidFrame v 1.0.0
8: * @copyright Copyright (c), PHPLucidFrame.
9: * @link http://phplucidframe.com
10: * @license http://www.opensource.org/licenses/mit-license.php MIT License
11: *
12: * This source file is subject to the MIT license that is bundled
13: * with this source code in the file LICENSE
14: */
15:
16: use LucidFrame\Core\Form;
17:
18: /**
19: * Initialize form
20: * @return void
21: */
22: function form_init()
23: {
24: Form::init();
25: }
26:
27: /**
28: * Setter for the class properties
29: * @param string $key The property name
30: * @param mixed $value The value to be set
31: * @return void
32: */
33: function form_set($key, $value = '')
34: {
35: Form::set($key, $value);
36: }
37:
38: /**
39: * Form token generation
40: * @return void
41: */
42: function form_token()
43: {
44: Form::token();
45: }
46:
47: /**
48: * Form token validation
49: * @param array $validations The array of validation rules
50: * @param array $data The optional data array (if no `value` in $validation, it will be looked up in $data)
51: * @return boolean
52: */
53: function form_validate($validations = null, $data = [])
54: {
55: return Form::validate($validations, $data);
56: }
57:
58: /**
59: * AJAX form responder
60: * @param string $formId The HTML form ID
61: * @param array $errors The array of the errors (it is used only for generic form processing)
62: * @param bool $forceJson Send json header
63: * @return void
64: */
65: function form_respond($formId, $errors = null, $forceJson = false)
66: {
67: Form::respond($formId, $errors, $forceJson);
68: }
69:
70: /**
71: * Permits you to set the value of an input or textarea.
72: * Allows you to safely use HTML and characters such as quotes within form elements without breaking out of the form
73: *
74: * @param string $name The input element field name
75: * @param mixed $defaultValue The default value of the input element (optional)
76: *
77: * @return mixed The value of the input element
78: */
79: function form_value($name, $defaultValue = null)
80: {
81: return Form::value($name, $defaultValue);
82: }
83:
84: /**
85: * Permits you to set the value to a rich text editor or any input where HTML source is required to be rendered.
86: * Allows you to safely use HTML and characters such as quotes within form elements without breaking out of the form
87: *
88: * @param string $name The input element field name
89: * @param mixed $defaultValue The default value of the input element (optional)
90: *
91: * @return mixed The value of the input element
92: */
93: function form_htmlValue($name, $defaultValue = null)
94: {
95: return Form::htmlValue($name, $defaultValue);
96: }
97:
98: /**
99: * Allow you to select the option of a drop-down list.
100: *
101: * @param string $name The field name of the drop-down list
102: * @param mixed $value The option value to check against
103: * @param mixed $defaultValue The default selected value (optional)
104: *
105: * @return string `'selected="selected"'` if the option is found, otherwise the empty string returned
106: */
107: function form_selected($name, $value, $defaultValue = null)
108: {
109: return Form::inputSelection($name, $value, $defaultValue) ? 'selected="selected"' : '';
110: }
111:
112: /**
113: * Allow you to select a checkbox or a radio button
114: *
115: * @param string $name The field name of the checkbox or radio button
116: * @param mixed $value The value to check against
117: * @param mixed $defaultValue The default selected value (optional)
118: *
119: * @return string `'checked="checked"'` if the option is found, otherwise the empty string returned
120: */
121: function form_checked($name, $value, $defaultValue = null)
122: {
123: return Form::inputSelection($name, $value, $defaultValue) ? 'checked="checked"' : '';
124: }
125: