1.

How Can You Add Validations In Phalcon?

Answer»

PhalconValidation is an independent validation component that validates an ARBITRARY set of data. This component can be used to implement validation RULES on data OBJECTS that do not belong to a MODEL or collection.

The following example shows its basic usage:

<?php
use PhalconValidation;
use PhalconValidationValidatorEmail;
use PhalconValidationValidatorPresenceOf;
$validation = new Validation();
$validation->add(
"name",
new PresenceOf(
[
"message" => "The name is required",
]
)
);
$validation->add(
"EMAIL",
new PresenceOf(
[
"message" => "The e-mail is required",
]
)
);
$validation->add(
"email",
new Email(
[
"message" => "The e-mail is not valid",
]
)
);
$messages = $validation->validate($_POST);
if (count($messages)) {
foreach ($messages as $message) {
echo $message, "<br>";
}
}

PhalconValidation is an independent validation component that validates an arbitrary set of data. This component can be used to implement validation rules on data objects that do not belong to a model or collection.

The following example shows its basic usage:

<?php
use PhalconValidation;
use PhalconValidationValidatorEmail;
use PhalconValidationValidatorPresenceOf;
$validation = new Validation();
$validation->add(
"name",
new PresenceOf(
[
"message" => "The name is required",
]
)
);
$validation->add(
"email",
new PresenceOf(
[
"message" => "The e-mail is required",
]
)
);
$validation->add(
"email",
new Email(
[
"message" => "The e-mail is not valid",
]
)
);
$messages = $validation->validate($_POST);
if (count($messages)) {
foreach ($messages as $message) {
echo $message, "<br>";
}
}



Discussion

No Comment Found