adamwathan / form

Super basic form HTML builder, only really exists so I can pull it in for some other more useful projects.
MIT License
232 stars 118 forks source link

Why there is no method validate to know if all form fields are "OK" ? #29

Closed RobinDev closed 9 years ago

RobinDev commented 9 years ago

Hello,

First, thanks for sharing your code.

I am interesting in your class but I am aksing me : Why there is no 'magic' function to check if all the form elements are valids.

Eg. :

<?php
//src/AdamWathan/Form/FormBuilder.php
namespace AdamWathan\Form;
...

    /**
     * Check if an error exist
     * @param mixed $name Null if you want to know if there is an error for all fields else 
     *                                      string corresponding to field name
     * @return bool
     */
    public function hasError($name = null)
    {
        if (! isset($this->errorStore)) {
            return false;
        }
        if ($name !== null) {
            return $this->errorStore->hasError($name);
        }

        return true;
    }
...

I am curious to know how you are doing. Else, if you judge this new feature and modification relevant, I can submit a pull-request.

Thanks for your time.

RobinDev commented 9 years ago

I re-read the code and I see there is no form validator.

It's look like it's not the goal of this package. I will make a class wich wrap this one plus a validator class to avoid to define twice things like min, max...