Custom Validation Class Printing Error Message in Any Case

I have created a Class for a form extending the Phalcon\Forms\Form.

I have created a Custom Validation class to validate the above form extending Phalcon\Validation

When I add data to form, submit it and try to validate the $_POST array it populates the $messages variable even in the case where I submit valid data.


What is question ?

edited Nov '14

$messages = $validation->validate($_POST);

If count($messages) is greater than 0 then I am printing the error messages and reloading the Form. but say I enter all valid data then the $messages array should ideally be empty and count($messages) should return 0, but this is not happening $messages still contains the error messages....has such issue been encountered before?

thanks in advance.


May be not recive data,but I recommed you method bind of Phalcon

$form = new UserForm($object);
        $form->bind($_POST, $object);

        //  Form isn't valid
        if (!$form->isValid($this->request->getPost())) {
            foreach ($form->getMessages() as $message) {

Thanks, Duy. Now my validation is in a separate custom validation class...will that work in this case? Is there a way to bind the Validation object to the Form object?

Could someone please help me? I am stuck. When I call

$messages = $validation->validate($_POST);

$messages is always populated with error messages no matter I enter correct or wrong data in the form.


edited Nov '14

My Validation class is

use Phalcon\Validation,
use Phalcon\Validation\Validator\Regex;

 class MemberBulkFormAddVal extends Validation
     public function initialize()
        for ($i = 1; $i <= MEMBER_BULK_ADD_COUNT; $i++) {
            $this->add('member_first_name_$i', new PresenceOf(array(
                'message' => "The First name is required $i"

            $this->add('member_first_name_$i', new Regex(array(
                'message' => "The First name is invalid $i",
                'pattern' => '/^[A-Za-z ]*$/'

            $this->add('member_last_name_$i', new PresenceOf(array(
                'message' => "The Last name is required $i"

My Form Class is

use Phalcon\Forms\Form,
use Phalcon\Validation;

use Phalcon\Forms\Element\Check;

class MemberBulkAddForm extends Form
     * Forms initializer
     * @param Member $user
     * @param array $options
    public function initialize($user, $options)
        for ($i = 1; $i <= MEMBER_BULK_ADD_COUNT; $i++) {
            $fname = new Text("member_first_name_$i", array('maxlength' => 30 ));

            $lname = new Text("member_last_name_$i", array('maxlength' => 30 ));


        $submit = new Submit("submit");


How do I link the 2?