Form setValidation is not work correctly #12465

Closed
mbrostami opened this Issue Dec 9, 2016 · 4 comments

Projects

None yet

3 participants

@mbrostami
Contributor

When I want to use setValidation for form, it doesn't validate elements!

CustomForm.php

<?php

use Phalcon\Forms\Form;
use Phalcon\Forms\Element\Text;

class CustomForm extends Form
{
    public function initialize($entity = null, $options = array())
    {
        $this->add(new Text("name"));
    }
}

CustomValidation.php

<?php

use Phalcon\Validation;
use Phalcon\Validation\Validator\PresenceOf;

class CustomValidation extends Validation
{
    public function initialize()
    {
        $this->add('name', new PresenceOf([
            'message' => 'Name is required'
        ]));
    }
}

Controller

class IndexController extends Controller
{
    public function testAction()
    {
        $customForm = new CustomForm();
        $customForm->setValidation(new CustomValidation());
        $customForm->isValid($this->request->getPost()); // BUG: if you don't post name, this line returns true! 
    }
}
@Jurigag
Contributor
Jurigag commented Dec 9, 2016

https://github.com/phalcon/cphalcon/blob/master/phalcon/forms/form.zep#L256

This is current implementation of isValid method. It's just expecting any validators added to elements, if you didnt added anything then nothing will be validated.

@mbrostami mbrostami referenced this issue Dec 9, 2016
Merged

Form validation some fixes #12466

3 of 3 tasks complete
@mbrostami
Contributor

So why there is a PUBLIC setter/getter for validation in form.zep!!!

@Jurigag
Contributor
Jurigag commented Dec 9, 2016 edited

I don't know. I didn't implement this.

@sergeyklay sergeyklay added this to the 3.0.3 milestone Dec 20, 2016
@sergeyklay
Collaborator

Fixed in the 3.0.x branch. Thanks you

@sergeyklay sergeyklay closed this Dec 20, 2016
@sergeyklay sergeyklay self-assigned this Dec 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment