-
Notifications
You must be signed in to change notification settings - Fork 1
Messages
MohammadAli Arjomand edited this page Jul 29, 2023
·
1 revision
You can use messages by messages
property, like ...
var_dump($pouria->messages);
For listing messages you can do like it
<?php if (!$pouria->check) { ?>
<ul>
<?php foreach ($pouria->messages as $message) { ?>
<li><?php echo $message; ?></li>
<?php } ?>
</ul>
<?php } ?>
You can use any languages in Pouria valid
For create a custom language you must write a JSON like it
{
"CONDITION_NAME" : "MESSAGE"
}
For example ...
{
"required" : "Field is required",
"min" : "Field length must be greater"
}
And you can use :key
for field name and :value
for condition value
{
"required" : ":key is required",
"min" : ":key length must be greater than :value"
}
Currently, you must import json file to pouria valid
$pouria->messages(json_decode(file_get_contents("JSON_FILE_PATH")));
This code must be before conditions
↑↑↑
Persian messages is ready!
For use it, you must add this code before conditions
$pouria->messages(json_decode(file_get_contents("https://raw.githubusercontent.com/mohammadali-arjomand/pouria-valid/main/languages/persian.json")));
You can use labels for change fields names in messages, like
$pouria->labels([
"name" => "Name",
"email" => "E-Mail",
"password" => "Password"
]);
In this code, if validation send a message, Name
is written instead name
, E-Mail
instead email
and Password
instead password
And you can use labels for translate fields names in messages, like
$pouria->labels([
"name" => "نام",
"email" => "رایانامه",
"password" => "گذرواژه"
]);
MIT License, Copyright (c) 2023 MohammadAli Arjomand