public function onPreSetData(FormEvent $event) { $form = $event->getForm(); if ($this->account->isRothIraType() || $this->account->isTraditionalIraType()) { $form->add($this->factory->createNamed('distribution_method', 'choice', null, array('choices' => Distribution::getDistributionMethodChoices(), 'expanded' => true, 'multiple' => false, 'required' => false)))->add($this->factory->createNamed('federal_withholding', 'choice', null, array('choices' => Distribution::getFederalWithholdingChoices(), 'expanded' => true, 'multiple' => false, 'required' => false)))->add($this->factory->createNamed('state_withholding', 'choice', null, array('choices' => Distribution::getStateWithholdingChoices(), 'expanded' => true, 'multiple' => false, 'required' => false)))->add($this->factory->createNamed('federal_withhold_percent', 'percent', null, array('required' => false)))->add($this->factory->createNamed('federal_withhold_money', 'number', null, array('precision' => 2, 'grouping' => true, 'required' => false)))->add($this->factory->createNamed('state_withhold_percent', 'percent', null, array('required' => false)))->add($this->factory->createNamed('state_withhold_money', 'number', null, array('precision' => 2, 'grouping' => true, 'required' => false)))->add($this->factory->createNamed('residenceState', 'entity', null, array('class' => 'WealthbotAdminBundle:State', 'label' => 'State', 'empty_value' => 'Select a State', 'required' => false))); } }
/** * Validate federal_withholding and child fields */ private function validateFederalWithholding() { if ($this->form->has('federal_withholding')) { $federalWithholding = $this->data->getFederalWithholding(); if (!in_array($federalWithholding, array_keys(Distribution::getFederalWithholdingChoices()))) { $this->form->get('federal_withholding')->addError(new FormError('Choose an option.')); } else { if ($federalWithholding == Distribution::FEDERAL_WITHHOLDING_TAXES) { $percentRate = $this->data->getFederalWithholdPercent(); $moneyRate = $this->data->getFederalWithholdMoney(); if (!is_numeric($percentRate) && !is_numeric($moneyRate)) { $this->form->get('federal_withholding')->addError(new FormError('Please enter withhold taxes rate.')); } elseif (is_numeric($percentRate) && is_numeric($moneyRate)) { $this->form->get('federal_withholding')->addError(new FormError('Please enter percent or money withhold taxes rate.')); } } elseif ($federalWithholding != Distribution::FEDERAL_WITHHOLDING_TAXES) { $this->data->setFederalWithholdPercent(null); $this->data->setFederalWithholdMoney(null); } } } }