jbroadway / elefant

Elefant, the refreshingly simple PHP CMS and web framework.
http://www.elefantcms.com
MIT License
208 stars 39 forks source link

Form validation: Allow multiple error messages per field #267

Closed jbroadway closed 8 years ago

jbroadway commented 8 years ago

If we make one addition to the form validation syntax, we can easily allow multiple validation error messages per field without requiring custom validations in PHP (which would also allow them to work client-side too). Here's an example:

[email]
not empty = 1 ; failed[] = email

[email:email-invalid]
email = 1 ; failed[] = email-invalid

This would correspond to the following template code:

<p>
    <label>{"Email address"}</label><br />
    <input type="email" name="email" value="{{email}}" />
    <span class="notice" id="email-notice">{"Please enter an email address."}</span>
    <span class="notice" id="email-invalid-notice">{"Please enter a valid email address."}</span>
</p>

Nothing else ought to need changing in the Form API for this to work.

AxorB commented 8 years ago

Very appreciated feature!