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