Download the PHP package priteshyadav444/validation without Composer

On this page you can find all versions of the php package priteshyadav444/validation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package validation

Php Validation Library

The library is inspired by Laravel validation and provides limited but similar functionality for form validation. It allows developers to define validation rules in a simple, human-readable format (e.g. "required|numeric") and quickly validate user input. This helps to ensure that the data entered into forms is accurate, consistent, and meets certain standards, improving the overall user experience and reducing the risk of errors in the application.

This library provides classes for validating different types of data inputs in PHP. It includes the following classes:

Features

Requirements

Usage - How to use in core Php Form Validation

FormValidator Class

The FormValidator class uses the Validate class to validate form inputs and return errors using Error Class. How to Use :

1) Include the FormValidator class in your code by using require or include statement. 2) Create an instance of the FormValidator class and store it in a variable. 3) Call the validate method on the instance of the FormValidator class and pass the form data and validation rules to it as arguments. 4) The validate method will validate the form data based on the rules and return true if the data is valid, and false otherwise. 5) If the validate method returns false, you can access the error messages using the errors method on the instance of the FormValidator class.

FormValidator class uses ErrorHandler Class to Handle Error : Using isErro() method and all() we can list errors :

if ($obj->isError() != false) {
        echo '<div class="alert alert-danger" role="alert">';
        foreach ($obj->all() as $error)
            echo "<li>$error</li>";
        echo '</div>';
}

To populate old value which was valid we can use old() method.

ErrorHandler Class

The ErrorHandle class provides functions to handle and store error messages. The class has functions to set error messages, return all error messages, check if errors exist, and handle error messages.

  1. isError() : method checks if there are any errors stored in the object's $errors array and returns a boolean value indicating the presence of errors. If a $key is passed as a parameter, it will check if there are any errors stored for that specific key in the $errors array and return a boolean value accordingly.
  2. all() : method returns an array of all error messages stored in the object's $errors array.
  3. old($key): The old method is a function in a PHP class used to return old values if the data was valid. It takes a single parameter, $key, which is used to retrieve the value from an array called oldValues.

Validate Class

This is a PHP class named "Validate" that provides functions to validate different data types (integer, float, string, email, password) and also functions to get different data types (integer, string, length). The class also includes error handling functionality through inheritance of the "ErrorHandler" class. Following method :

  1. isInt: Validates whether the input is an integer or not.

  2. isfloat: Validates whether the input is a floating-point number or not.

  3. isString: Validates whether the input is a string or not.

  4. isEmail: Validates whether the input is a valid email address or not.

  5. getInt: Returns the input as an integer, floating-point number or boolean (false) if it is not valid.

  6. getString: Returns the input as a string or boolean (false) if it is not a valid string.

  7. getLength: Returns the length of the input.

  8. checkMinimum: Checks if the length of the input is greater than or equal to the specified length.

  9. checkMaximum: Checks if the length of the input is less than or equal to the specified length.

  10. checkPassword: Validates the input as a password according to the specified regular expression.

  11. extractInteger: Extracts only the integer part from the input.

  12. extractFloat: Extracts only the floating-point number part from the input.
  13. senitizeInput : method is a security measure used to sanitize user input. It performs the following operations in the given order:

    • Removes any whitespace from the beginning and end of the input string with trim().

    • Strips backslashes (\) from the input string with stripslashes().
    • Converts any special HTML characters in the input string to their corresponding HTML entities with htmlspecialchars().

The purpose of these operations is to make sure that the input data is free from any malicious content, such as scripts, that could potentially harm the application. The method returns the sanitized input as the result.

Steps to Add custom validation in this library:

1) Create a validation method in the Validate Class that returns a boolean value. For example: public function checkEmail():bool in the Validate class.

2) Map the validation key to the validation type in the match function inside getValidationType() in the FormValidation Class. For example, 'email' => CHECK_EMAIL.

3) Map the $validationType to an error code in the getErrorMessage() method in the errorHandler class. For example, 'CHECK_EMAIL' => 'INVALID_DATATYPE_KEY'.

4) Map the $errorCode to an error message in the $errorHandler property in the errorHandler class.. For example, 'INVALID_DATATYPE_KEY' => 'Invalid Data types'.

5) Add a conditional statement for $validationType (CHECK_EMAIL) in the performValidation() method in FormValidator.

Important Notice for Library Users

Please be aware that this library has not been fully tested and may contain bugs. If you encounter any issues while using this library, we kindly request that you report them in the Issues section of this repository. This will allow us to identify and resolve any problems as soon as possible.

Thank you for your understanding and cooperation.


All versions of validation with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package priteshyadav444/validation contains the following files

Loading the files please wait ...