Posted on 4th November 2009No Responses
Symfony: Allowing extra field in validated forms

A quick hint: it unnerves me when I have to add a new field to a that does not belong to the model and thus always fires a validator error. Since I don’t have time and don’t want to create a whole validator array for my rather big , I used

$this->validatorSchema->setOption('allow_extra_fields', true);

to allow extra fields in my . Use only if you do otherwise or if the fields you add aren’t critical if they aren’t validated (e.g. in my case a <select>)

EDIT: it seems that when using the code above, the added fields are not added to $ (or, in fact, not sent back to the action). as soon as I figure out a fix, I’ll update this post.

EDIT: i’ve found the source of the problem: allow_extra_fields allows for adding the fields, but filters them before processing the $ item, so we have to add:

$this->validatorSchema->setOption('filter_extra_fields', false);

to make it work, since only in this manner the filtering is disabled and the data is submitted.

Share this on:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Add to favorites
  • email
  • MisterWong
  • MySpace
  • Reddit
  • RSS
  • Yahoo! Bookmarks

Related posts

Comments
Leave a Response
XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <img src="">