<commit_before># FormValidate
Basic form validation in PHP


## Usage

1. Include the class `src/classes/Form.class.php` wherever you need the PHP form validator.

2. Create the rules array for your existing form:


```php
$rules = [];
$rules["input_name"] = [
    "required" => true,
    "minlength" => 3,
    "maxlength" => 100,
    "alphabetical" => true,
    "label" => "name",
    ];
```

Existing rule keys are:

- `required` *boolean* - If set to true, the field must not be empty when submitting the form
- `empty` *boolean* - If set to true, the field must be empty when submitting the form
- `minlength` *integer* - Sets a minimal length for the field value
- `maxlength` *integer* - Sets a maximal length for the field value
- `alphabetical` *boolean* - If set to true, the field must only include alpabetical letters (a-z or A-Z), have a minimal length of 2 and may contain spaces
- `number` *boolean* - If set to true, the field value must be numeric
- `email` *boolean* - If set to true, the field value must match an email address. `FILTER_VALIDATE_EMAIL` is used for validation
- `phone` *boolean* - If set to true, the field value must match a phone number with a length between 3 to 18 characters. The characters can include a `+` in the beginning `-`, `space` or parantheses (`(` and `)`).
- `label` *string* - Sets the label contained in the error message


3. Initialize the form validator with the `$_POST` data and the created rules:

```php
$Form = new Form($_POST, $rules);
```

4. `$Form->validate()` returns `true` if the validation has been successfully done. If errors occur during the validation, `$Form->getErrors()` will return an `array` with at least one entry.<commit_msg>Add namespace usage in README<commit_after># FormValidate
Basic form validation in PHP


## Usage

1. Include the class from `src/classes/Form.class.php` wherever you need the PHP form validator.

2. Create the rules array for your existing form:


```php
$rules = [];
$rules["input_name"] = [
    "required" => true,
    "minlength" => 3,
    "maxlength" => 100,
    "alphabetical" => true,
    "label" => "name",
    ];
```

Existing rule keys are:

- `required` *boolean* - If set to true, the field must not be empty when submitting the form
- `empty` *boolean* - If set to true, the field must be empty when submitting the form
- `minlength` *integer* - Sets a minimal length for the field value
- `maxlength` *integer* - Sets a maximal length for the field value
- `alphabetical` *boolean* - If set to true, the field must only include alpabetical letters (a-z or A-Z), have a minimal length of 2 and may contain spaces
- `number` *boolean* - If set to true, the field value must be numeric
- `email` *boolean* - If set to true, the field value must match an email address. `FILTER_VALIDATE_EMAIL` is used for validation
- `phone` *boolean* - If set to true, the field value must match a phone number with a length between 3 to 18 characters. The characters can include a `+` in the beginning `-`, `space` or parantheses (`(` and `)`).
- `label` *string* - Sets the label contained in the error message


3. Initialize the form validator with the `$_POST` data and the created rules:

```php
use webfashion\Form;
$Form = new Form($_POST, $rules);
```

4. `$Form->validate()` returns `true` if the validation has been successfully done. If errors occur during the validation, `$Form->getErrors()` will return an `array` with at least one entry.
{'fraction_non_alphanumeric': 0.11168981481481481, 'fraction_numerical': 0.006944444444444444, 'mean_word_length': 3.8621659634317864, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6105310', 'n_tokens_mistral': 1034, 'n_tokens_neox': 989, 'n_words': 492}