The fact that I have entered into IT-related business is proof that businesses have to evolve and keep with time. One has to re-invent continuously.

Kerry Packer

Symfony: Unbound sfForm: Unexpected extra form field named

Looking for a Symfony Developer?

If you or your company are looking for a Symfony Developer contact us or read about our Symfony Development Service

Symfony: Unbound sfForm: Unexpected extra form field named key visual


Ever tried creating an unbound form in Symfony and received the "Unexpected extra form field named" error? This article shows you how to add extra fields to a Symfony sfForm. Safely!

In this use case we have an exiting model that describes an Article. We want to be able edit the Article and have the option to send and email to an address defined in a text box. However we don't want the email field to be bound to the form and we dont want to add the email address to the Article.

So we add a field to our form like so:

class ArticleForm extends BaseArticleForm
  public function configure()
    $this->widgetSchema['email'] = new sfWidgetFormInputText();

This displays our field nicely and we can enter the email address. However we get a an "Unexpected extra form field named" error. That is because as the form is being validated it finds the email field however no sfValidator to ensure that it is valid.

We fix this by adding an sfValidator* to check the field. We can add one of sfValidatorPass or better still sfValidatorEmail. This will fix the "Unexpected extra form field named" issue and keep Symfony happy

class ArticleForm extends BaseArticleForm
  public function configure()
    $this->widgetSchema['email'] = new sfWidgetFormInputText();
    $this->validatorSchema['email'] = new sfValidatorPass();

I hope that you find this helpful.

If you found this article useful, please be sure to check out the related articles below.

seddik commented:

it helped me thanx

andrew commented:

thanks for this wonderful post.

it help me a lot.

SoGua commented:

Nice one! And i face another problem. How can i reorder the form fields including these extra form fields?

Adam Pullen commented:

Hello SoGua,

If you are talking about the "presentation" of the fields, I would suggest that you use your HTML skills to lay the fields out how you want them.

However you can also use the sfForm::useFields method. By default it will order the fields in the order that you specify them in the array.


$form->useFields(array('firstname', 'lastname', 'age'));

will present order them in 

1) firstname,

2) lastname,

3) age

I find this method of "useField" a bit bothersome as you always have to remember to include the _csrf_token, id and other fields. 

As this is a public method you are also free to call it from your action. Just remember if you do do this from your action you have to "setup" the form on both the "show form (executeEdit)" action and the "update form (executeEdit)" 

I hope that this helps

You can read the official documentation here:

SoGua commented:

Thanks a lot!

David E. Narvaez commented:

Thanks, this saved me a lot of time.

votoan commented:

Thanks a lot!

mangel commented:

Good tip when is not required validate the field.


John commented:

Saved me the day! Thanks!

Samrat commented:

Thanks a lot!

Tapper commented:

In this snippet is also nicely explained how to prevent saving the extra value:

Basically, the way is overriding the updateYourFieldHereColumn() method.

Dave commented:

Thanks, this helped a lot.

noName commented:

This helped me a lot!!! Thanks!!!

harry commented:

Can I discover a need best custom writing from done your advice? There are so numerous of these external there besides I am mistaken about which sole to share. I would nay need to cull proper some liturgy besides complete up getting copied or humble character process.

bonton commented:

I am a enormous addict of your blogs mainly so I consider what you remark is the gospel fact as deep as school writing goes. I show an inspection that I discovered moot. From my skill beside this point, the dutys are very amazing. Control it external satisfy.

KENRICK commented:

How exactly does you figure out to generate an important hot essay writer? As a result of a slope in thinking about, it will be complicated good enough aiming to craft the person article besides collecting a top article product. Reckon many athletic different and even it is not a item.

CASSIE commented:

Regards for all the amazing articles or content; many in fact turn considerably through showing you and me latest important things. One example is, I just read through some blog page on the subject of bestessays it departed everybody asking. Can you expound further on that system?

Add a comment

Your email will not be published