You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When using $form->isValid() to validate form and you have a validation class with beforeValidation() method, you get error: Trying to call method count on a non-object
let messages = validation->validate(data, entity);
if messages->count() {
and expects back a Phalcon\Messages object.
In the Phalcon\Filter\Validation class, in the validate() method, the messages variable is getting passed along to event beforeValidation and once the status returned from validate() is false (as per documentation), the messages do not get returned back.
* Implicitly creates a Phalcon\Messages\Messages object
*/
let messages =newMessages();
if entity !==null {
this->setEntity(entity);
}
/**
* Validation classes can implement the 'beforeValidation' callback
*/
if method_exists(this, "beforeValidation") {
let status =this->{"beforeValidation"}(data, entity, messages);
if status ===false {
return status;
}
}
letthis->messages = messages;
Not entirely sure but, is it not possible to do something along the lines
// Phalcon\Forms\Form
/**
* Perform the validation
*/
let result = validation->validate(data, entity);
if result === false {
let messages = validation->getMessages();
} else {
let messages = result;
}
if messages->count() {
// Add validation messages to relevant elements
for elementMessage in iterator(messages) {
this->get(elementMessage->getField())->appendMessage(elementMessage);
}
messages->rewind();
let validationStatus = false;
}
and also
// Phalcon\Filter\Validation
/**
* Implicitly creates a Phalcon\Messages\Messages object
*/
let this->messages = new Messages();
if entity !== null {
this->setEntity(entity);
}
/**
* Validation classes can implement the 'beforeValidation' callback
*/
if method_exists(this, "beforeValidation") {
let status = this->{"beforeValidation"}(data, entity);
if status === false {
return status;
}
}
and use this->appendMessage() in the event method instead.
The text was updated successfully, but these errors were encountered:
Describe the bug
When using
$form->isValid()
to validate form and you have a validation class withbeforeValidation()
method, you get error:Trying to call method count on a non-object
To Reproduce
Steps to reproduce the behavior:
As per documentation https://docs.phalcon.io/5.8/filter-validation/#events
Details
Additional context
The issue starts from
$form->isValid()
whenvalidation->validate(data, entity);
is being calledcphalcon/phalcon/Forms/Form.zep
Lines 719 to 723 in 83677f1
and expects back a
Phalcon\Messages
object.In the
Phalcon\Filter\Validation
class, in thevalidate()
method, themessages
variable is getting passed along to eventbeforeValidation
and once thestatus
returned fromvalidate()
is false (as per documentation), themessages
do not get returned back.cphalcon/phalcon/Filter/Validation.zep
Lines 501 to 521 in 83677f1
Not entirely sure but, is it not possible to do something along the lines
and also
and use
this->appendMessage()
in the event method instead.The text was updated successfully, but these errors were encountered: