├── boot.php ├── install.php ├── package.yml ├── .github └── workflows │ └── publish-to-redaxo-org.yml ├── lib ├── yform │ └── value │ │ └── direct_input.php └── standalone_validator.php ├── LICENSE └── README.md /boot.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /install.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /package.yml: -------------------------------------------------------------------------------- 1 | package: yform_standalone_validator 2 | version: '1.1.0' 3 | author: 'Friends Of REDAXO' 4 | supportpage: https://github.com/FriendsOfREDAXO/yform_standalone_validator 5 | 6 | requires: 7 | redaxo: '^5.9' 8 | php: '>=8.0' 9 | yform: '^4,<5' -------------------------------------------------------------------------------- /.github/workflows/publish-to-redaxo-org.yml: -------------------------------------------------------------------------------- 1 | # Instructions: https://github.com/FriendsOfREDAXO/installer-action/ 2 | 3 | name: Publish to REDAXO.org 4 | on: 5 | release: 6 | types: 7 | - published 8 | 9 | jobs: 10 | redaxo_publish: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v2 14 | - uses: FriendsOfREDAXO/installer-action@v1 15 | with: 16 | myredaxo-username: ${{ secrets.MYREDAXO_USERNAME }} 17 | myredaxo-api-key: ${{ secrets.MYREDAXO_API_KEY }} 18 | description: ${{ github.event.release.body }} 19 | 20 | -------------------------------------------------------------------------------- /lib/yform/value/direct_input.php: -------------------------------------------------------------------------------- 1 | value = $this->getElement(2); 8 | } 9 | 10 | public function enterObject(): void 11 | { 12 | $this->params['value_pool']['email'][$this->getName()] = $this->getValue(); 13 | $this->params['value_pool']['sql'][$this->getName()] = $this->getValue(); 14 | } 15 | 16 | public function getDescription(): string 17 | { 18 | return ' 19 | direct_input -> Beispiel: direct_input|name|value 20 | '; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Friends Of REDAXO 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Standalone Validator (YForm-Erweiterung) 2 | 3 | __Erweiterung__ für das REDAXO-Addon [yform](https://github.com/yakamara/redaxo_yform): Ermöglicht das Validieren von PHP Arrays ohne HTML Formulare. Es können alle YForm Validierungen genutzt werden. 4 | 5 | ## Beispiel 6 | ```php 7 | $input = [ 8 | 'first_name' => 'Max', 9 | 'last_name' => 'Mustermann' 10 | ]; 11 | 12 | $rules = [ 13 | ['empty' => ['first_name', 'Bitte Vornamen angeben.']], 14 | ['empty' => ['last_name', 'Bitte Nachnahmen angeben.']] 15 | ]; 16 | 17 | $validator = new standalone_validator(); 18 | 19 | $validator->setValueArray($input); 20 | $validator->setValidationArray($rules); 21 | 22 | if(!$validator->isValid()) { 23 | print_r($validator->getErrors()); 24 | } 25 | 26 | ``` 27 | 28 | Installation 29 | ------- 30 | 31 | * Paket herunterladen oder über den Installer installieren 32 | 33 | 34 | Changelog 35 | ------- 36 | 37 | ### Version 1.1.0 // 03.12.2023 38 | 39 | * Anpassung für YForm 4 40 | 41 | 42 | ### Version 1.0.1 // 14.07.2019 43 | 44 | * Anpassung für YForm 3.1.1 45 | 46 | ### Version 1.0.0 // 18.03.2017 47 | 48 | * Umstellung auf eigenständiges AddOn 49 | * Ausgabe Fehlermeldungen als assoziatives Array 50 | 51 | ### Version 0.1 // 26.07.2016 52 | 53 | * Initial release 54 | -------------------------------------------------------------------------------- /lib/standalone_validator.php: -------------------------------------------------------------------------------- 1 | $val) { 11 | $this->setValueField('direct_input', [$key, $val]); 12 | $this->fieldNames[$i] = $key; 13 | ++$i; 14 | } 15 | } 16 | 17 | public function setValidationArray($arr): void 18 | { 19 | foreach ($arr as $item) { 20 | foreach ($item as $key => $val) { 21 | $this->setValidateField($key, $val); 22 | } 23 | } 24 | } 25 | 26 | public function validate(): void 27 | { 28 | $this->objparams['values'] = []; 29 | $this->objparams['validates'] = []; 30 | $this->objparams['actions'] = []; 31 | $this->objparams['fields'] = []; 32 | $this->objparams['fields']['values'] = &$this->objparams['values']; 33 | $this->objparams['fields']['validates'] = &$this->objparams['validates']; 34 | $this->objparams['fields']['actions'] = &$this->objparams['actions']; 35 | $this->objparams['send'] = 1; 36 | 37 | $rows = count($this->objparams['form_elements']); 38 | 39 | for ($i = 0; $i < $rows; ++$i) { 40 | $element = $this->objparams['form_elements'][$i]; 41 | 42 | if ('validate' == $element[0]) { 43 | $class = 'rex_yform_validate_' . trim($element[1]); 44 | } else { 45 | $class = 'rex_yform_value_' . trim($element[0]); 46 | } 47 | 48 | if (class_exists($class)) { 49 | if ('validate' == $element[0]) { 50 | $class = 'rex_yform_validate_' . trim($element[1]); 51 | $this->objparams['validates'][$i] = new $class(); 52 | $this->objparams['validates'][$i]->loadParams($this->objparams, $element); 53 | $this->objparams['validates'][$i]->setId($i); 54 | $this->objparams['validates'][$i]->init(); 55 | $this->objparams['validates'][$i]->setObjects($this->objparams['values']); 56 | } else { 57 | $class = 'rex_yform_value_' . trim($element[0]); 58 | $this->objparams['values'][$i] = new $class(); 59 | $this->objparams['values'][$i]->loadParams($this->objparams, $element); 60 | $this->objparams['values'][$i]->setId($i); 61 | $this->objparams['values'][$i]->init(); 62 | $this->objparams['values'][$i]->setObjects($this->objparams['values']); 63 | $rows = count($this->objparams['form_elements']); 64 | } 65 | } else { 66 | echo 'Class does not exist "' . $class . '" '; 67 | } 68 | } 69 | 70 | foreach ($this->objparams['values'] as $i => $valueObject) { 71 | $valueObject->setValue($this->getFieldValue($i, [])); 72 | } 73 | 74 | foreach ($this->objparams['validates'] as $Object) { 75 | $Object->enterObject(); 76 | } 77 | 78 | $this->objparams['validated'] = 1; 79 | } 80 | 81 | public function getErrors(): array 82 | { 83 | if (!isset($this->objparams['validated']) || 1 != $this->objparams['validated']) { 84 | $this->validate(); 85 | } 86 | 87 | $warning_messages = $this->objparams['warning_messages']; 88 | $out = []; 89 | foreach ($warning_messages as $key => $val) { 90 | $out[$this->fieldNames[$key]] = $val; 91 | } 92 | 93 | return $out; 94 | } 95 | 96 | public function isValid(): bool 97 | { 98 | if (!isset($this->objparams['validated']) || 1 != $this->objparams['validated']) { 99 | $this->validate(); 100 | } 101 | 102 | if (count($this->objparams['warning'])) { 103 | return false; 104 | } 105 | 106 | return true; 107 | } 108 | } 109 | --------------------------------------------------------------------------------