/**
  * Validate frequency field
  */
 private function validateFrequency()
 {
     if ($this->form->has('frequency')) {
         $frequencyChoices = Distribution::getFrequencyChoices();
         if (!in_array($this->data->getFrequency(), array_keys($frequencyChoices))) {
             $this->form->get('frequency')->addError(new FormError('Choose an option.'));
         }
     }
 }
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $distribution = $builder->getData();
     if (null == $distribution->getFrequency()) {
         $distribution->setFrequency(Distribution::FREQUENCY_EVERY_OTHER_WEEK);
     }
     $this->factory = $builder->getFormFactory();
     $builder->add('frequency', 'choice', array('expanded' => true, 'label' => 'Frequency of transaction: ', 'choices' => Distribution::getFrequencyChoices()))->add('amount', 'money', array('attr' => array('class' => 'input-mini'), 'currency' => 'USD', 'label' => 'Amount: '));
     $builder->addEventListener(FormEvents::PRE_SET_DATA, array($this, 'onPreSetData'));
     $builder->addEventListener(FormEvents::BIND, array($this, 'onBindData'));
 }
 /**
  * Get choices for frequency field
  *
  * @return array
  */
 protected function getFrequencyChoices()
 {
     return array_reverse(Distribution::getFrequencyChoices(), true);
 }