Validating Checkboxes and Radiobuttons in Symfony

Months ago I wrote about the validation of checkboxes in Symfony and how it could fill your database with wrong values.

I recommended downloading, or writing, a small validator which checked if the value of the checkbox is zero or one. But there’s a much simpler solution to this problem.

If you use a numerical value for your radiobuttons/checkboxes, simply call the sfNumberValidator with zero as an minmum and one as an maximum.

tos:
  sfNumberValidator:
    min: 0
    max: 1

If you use strings, such as ‘male’ or ‘female’ for a gender radiobutton, the sfStringValidator is the right choice:

sfStringValidator:
  values: ['male', 'female']
  value_error: Invalid value

Published: April 2, 2008 — Tagged: , ,

Post a Comment

© 2008 Arthur Koziel — About | Archive | Colophon | Contact | Feeds

Bookmarks Bookmarks RSS Feed

IEBlog : IE8 Security Part IV: The XSS Filter
IE8 will include and enable an XSS filter by default. To disable it, a custom HTTP header needs to be set.
YAXML
YAXML is a perl script which transforms YAML into XML and back.
Visual language 1.0
PDF describing the BBC.co.uk global page restructure.