mitchellston/form_validation

这应该有助于在PHP中验证POST和GET请求!

1.0 2022-11-03 23:02 UTC

This package is auto-updated.

Last update: 2024-09-24 19:03:55 UTC


README

本项目旨在使POST和GET请求的验证变得更加容易。我们实现这一目标的方法是使验证的方式类似于HTML中的输入标签。

入门指南

以下说明将指导您使用此库创建一个可工作的项目。

先决条件

构建、测试和推送软件及其他工具的要求

  • PHP 7.4或更高版本
  • Composer

安装

一系列逐步示例,指导您如何运行开发环境。

启动composer项目

Composer init

使用composer安装库

Composer require mitchellston/form_validation

将库添加到composer的自动加载器(在composer.json中)

{
  "autoload": {
    "classmap": [
      "./vendor/mitchellston/"
    ]
  }
}

更新composer自动加载器

Composer update

演示

<?php
//Let's pretend the url is https://www.test.com?username=carl
require_once "../vendor/autoload.php";
use PostGetRequestValidation\Attributes;
use PostGetRequestValidation\Methods;
use PostGetRequestValidation\Types;
use PostGetRequestValidation\Validation;

$test = new Validation("username", Methods::GET, Types::TEXT, 
[
    Attributes::minLength => ["value" => 5, "errorMessage" => "A username needs to at least be 5 characters long!"]
]);
echo $test->getValue(); # carl
echo $test->getErrors(); # ["A username needs to at least be 5 characters long!"]
//Now you can send back the errors to your users

许可证

本项目采用MIT许可证[点击查看详细内容](https://github.com/mitchellston/form_validation/blob/HEAD/LICENSE) - 请参阅LICENSE文件以获取详细信息。