Phalcon is very good framework (in my opinion). I'm a beginner in working with frameworks. Phalcon's documentation is well and I've found answers on many questions just reading instructions and examples on the official website and github. A lot of examples of Validation has showed how to make validation by using Forms (or Models). I want create forms in Volt without Forms like this:
<h2>Sign up using this form</h2>
<div id="messages">{{ flash.output() }}</div>
{{ form("registration", "method":"post") }}
<p>
<label for="username">Name</label>
{{ text_field("username", "size": 32) }}
</p>
<p>
<label for="password">Password</label>
{{ text_field("password", "type": "password", "size": 32, "maxsize": 100) }}
</p>
<p>
{{ submit_button("Register") }}
</p>
{{ end_form() }}
First, I created "RegistrationValidation.php":
<?php
use Phalcon\Validation;
use Phalcon\Validation\Validator\Regex;
use Phalcon\Validation\Validator\StringLength;
class RegistrationValidation extends Validation
{
public function initialize()
{
$this
->add('name', new Regex([
'message' => 'The name is required',
'pattern' => '/\+44 [0-9]+/',
'allowEmpty' => true
]))
->add('name', new StringLength([
'messageMinimum' => 'The name is too short',
'min' => 2
]));
$this->setFilters('username', 'trim');
$this->setFilters('password', 'trim');
}
public function getMessages()
{
$messages = [];
foreach (parent::getMessages() as $message) {
switch ($message->getType()) {
case 'PresenceOf':
$messages[] = 'Заполнение поля ' . $message->getField() . ' обязательно';
break;
}
}
return $messages;
}
}
but what should I do next?
How can I flash messages from getMessages function (RegistrationValidation.php) in view and add validator in RegistrationController?
Or how can I create it in the RegistrationController, also flash messages in view and validate POST? I think, that shioud be done like this (by creating a function in the RegistrationController):
<?php
// ...
public function validate() {
// ...
}
// ...
but what's next? All attempts to find the right way brought me to a standstill. Help me please! Thanks a lot!