Question

I'm having problems in my register form. I have a choice field that is required to submit the form. In my form I have:

->add('playerPosition', 'choice', array(
    'choices' => array('Spelverdeler' => 'Spelverdeler', 'Receptie/Hoek' => 'Receptie/Hoek', 'Libero' => 'Libero', 'Midden' => 'Midden', 'Opposite' => 'Opposite', 'All-round' => 'All-round'),
    'label'         => 'Spelerspositie*',
    'empty_value' => 'Kies uw positie.',
    'required' => true
))

And when the form shows the value 'Kies uw positie.' is selected. But when you submit I don't get an error that it's required. (Because a value 'Kies uw positie.' is selected, but that's just the empty value ..)

I'm also using chosen on my select list just like this:

$('#register_player_playerPosition').chosen();

So what can I do that it doesn't see the empty value as a value? I need to have a 'empty value' that is not a valid value... So the user is forced to pick a choice.

Was it helpful?

Solution

You should use 'placeholder' instead of 'empty_value'

->add('playerPosition', 'choice', array(
    'choices' => array('Spelverdeler' => 'Spelverdeler', 'Receptie/Hoek' => 'Receptie/Hoek', 'Libero' => 'Libero', 'Midden' => 'Midden', 'Opposite' => 'Opposite', 'All-round' => 'All-round'),
    'label'         => 'Spelerspositie*',
    'placeholder' => 'Kies uw positie.',
    'required' => true
))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top