New validation class for Sprout 3. Used with the Validity class.
This is the code documentation for the SproutCMS project
Search documentation |
class ValidatorNew validation class for Sprout 3. Used with the Validity class.
Example// Multiedit example for a course with students $has_error = false; $valid = new Validator($_POST); $valid->required(['name']); $valid->check('name', 'Validity::length', 1, 100); if ($valid->hasErrors()) { $_SESSION['course_edit']['field_errors'] = $valid->getFieldErrors(); $valid->createNotifications(); $has_error = true; } if (empty($_POST['multiedit_students'])) { $_POST['multiedit_students'] = []; } $record_num = 0; foreach ($_POST['multiedit_students'] as $idx => $data) { if (MultiEdit::recordEmpty($data)) continue; ++$record_num; $multi_valid = new Validator($data); $multi_valid->setLabels([ 'name' => 'Name for student ' . $record_num, 'email' => 'Email address for student ' . $record_num, ]); $multi_valid->required(['name', 'email']); $multi_valid->check('name', 'Validity::length', 1, 100); $multi_valid->check('email', 'Validity::email'); if ($multi_valid->hasErrors()) { $_SESSION['course_edit']['field_errors']['multiedit_students'][$idx] = $multi_valid->getFieldErrors(); $multi_valid->createNotifications(); $has_error = true; } } if ($has_error) { Url::redirect('course/edit'); } Example// Plain example $valid = new Validator($_POST); $valid->required(['name', 'email']); $valid->check('name', 'Validity::length', 1, 100); $valid->check('email', 'Validity::email'); if ($valid->hasErrors()) { $_SESSION['register']['field_errors'] = $valid->getFieldErrors(); $valid->createNotifications(); Url::redirect('user/register'); } Source code (54 results)/modules/Demo/Controllers/MultiStepDemoController.php Highlighted file source Line 16: /modules/Welcome/Controllers/WelcomeController.php Highlighted file source Line 38: /sprout/Controllers/Admin/CategoryAdminController.php Highlighted file source Line 29: /sprout/Controllers/Admin/CategoryAdminController.php Highlighted file source Line 29: /sprout/Controllers/Admin/EmailTextAdminController.php Highlighted file source Line 18: /sprout/Controllers/Admin/EmailTextAdminController.php Highlighted file source Line 18: /sprout/Controllers/Admin/ExtraPageAdminController.php Highlighted file source Line 22: /sprout/Controllers/Admin/ExtraPageAdminController.php Highlighted file source Line 22: /sprout/Controllers/Admin/FileAdminController.php Highlighted file source Line 52: /sprout/Controllers/Admin/FileAdminController.php Highlighted file source Line 52: /sprout/Controllers/Admin/ManagedAdminController.php Highlighted file source Line 44: /sprout/Controllers/Admin/ManagedAdminController.php Highlighted file source Line 44: /sprout/Controllers/Admin/MySettingsAdminController.php Highlighted file source Line 26: /sprout/Controllers/Admin/MySettingsAdminController.php Highlighted file source Line 26: /sprout/Controllers/Admin/OperatorAdminController.php Highlighted file source Line 27: /sprout/Controllers/Admin/OperatorAdminController.php Highlighted file source Line 27: /sprout/Controllers/Admin/OperatorCategoryAdminController.php Highlighted file source Line 22: /sprout/Controllers/Admin/OperatorCategoryAdminController.php Highlighted file source Line 22: /sprout/Controllers/Admin/PageAdminController.php Highlighted file source Line 68: /sprout/Controllers/Admin/PageAdminController.php Highlighted file source Line 68: /sprout/Controllers/Admin/RedirectAdminController.php Highlighted file source Line 21: /sprout/Controllers/Admin/RedirectAdminController.php Highlighted file source Line 21: /sprout/Controllers/Admin/SubsiteAdminController.php Highlighted file source Line 22: /sprout/Controllers/Admin/SubsiteAdminController.php Highlighted file source Line 22: /sprout/Controllers/Controller.php Highlighted file source Line 32: /sprout/Controllers/Controller.php Highlighted file source Line 32: /sprout/Controllers/DbToolsController.php Highlighted file source Line 69: /sprout/Controllers/DbToolsController.php Highlighted file source Line 69: /sprout/Controllers/EmailShareController.php Highlighted file source Line 30: /sprout/Controllers/EmailShareController.php Highlighted file source Line 30: /sprout/Controllers/MultiStepFormController.php Highlighted file source Line 25: /sprout/Controllers/MultiStepFormController.php Highlighted file source Line 25: /sprout/Helpers/Form.php Highlighted file source Line 114: /sprout/Helpers/JsonForm.php Highlighted file source Line 266: /sprout/Helpers/Locales/LocaleInfo.php Highlighted file source Line 23: /sprout/Helpers/Locales/LocaleInfo.php Highlighted file source Line 23: /sprout/Helpers/Locales/LocaleInfoAUS.php Highlighted file source Line 16: /sprout/Helpers/Locales/LocaleInfoAUS.php Highlighted file source Line 16: /sprout/Helpers/Locales/LocaleInfoCAN.php Highlighted file source Line 17: /sprout/Helpers/Locales/LocaleInfoCAN.php Highlighted file source Line 17: /sprout/Helpers/Locales/LocaleInfoCHN.php Highlighted file source Line 17: /sprout/Helpers/Locales/LocaleInfoCHN.php Highlighted file source Line 17: /sprout/Helpers/Locales/LocaleInfoGBR.php Highlighted file source Line 17: /sprout/Helpers/Locales/LocaleInfoGBR.php Highlighted file source Line 17: /sprout/Helpers/Locales/LocaleInfoNZL.php Highlighted file source Line 16: /sprout/Helpers/Locales/LocaleInfoNZL.php Highlighted file source Line 16: /sprout/Helpers/Locales/LocaleInfoUSA.php Highlighted file source Line 17: /sprout/Helpers/Locales/LocaleInfoUSA.php Highlighted file source Line 17: /sprout/Helpers/Model.php Highlighted file source Line 17: /sprout/Helpers/Model.php Highlighted file source Line 17: /sprout/Helpers/Validator.php Highlighted file source Line 27: /sprout/Helpers/Validity.php Highlighted file source Line 26: /sprout/tests/validiatorTest.php Highlighted file source Line 14: /sprout/tests/validiatorTest.php Highlighted file source Line 14: A total of 226 lines in 54 files were found |
Powered by Pelzini, version 0.9.0 |
Documentation is made available under the
GNU Free Documentation License 1.2. Generated: Monday, 3rd April, 2023 at 02:59 pm |