public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $this->factory = $builder->getFormFactory();
     $builder->add('firstName', 'text', array('attr' => array('class' => 'input-medium', 'placeholder' => 'First Name'), 'required' => false))->add('middleName', 'text', array('attr' => array('class' => 'input-small', 'placeholder' => 'Middle Name'), 'required' => false))->add('lastName', 'text', array('attr' => array('class' => 'input-medium', 'placeholder' => 'Last Name'), 'required' => false))->add('birthDate', 'date', array('attr' => array('class' => 'jq-ce-date input-small', 'placeholder' => 'MM-DD-YYYY'), 'format' => 'MM-dd-yyyy', 'label' => 'Birth Date', 'required' => false, 'widget' => 'single_text'))->add('citizenship', 'choice', array('choices' => array('1' => 'Yes', '0' => 'No'), 'data' => 1, 'expanded' => true, 'label' => 'U.S. citizen?', 'property_path' => false, 'constraints' => array(new True(array('message' => 'Spouse of your client should be U.S. citizen.')))));
     $builder->add('employmentType', 'choice', array('choices' => Profile::getEmploymentTypeChoices(), 'expanded' => true, 'label' => 'Employment Status', 'multiple' => false, 'required' => true))->add('employerName', 'text', array('attr' => array('class' => 'input-medium'), 'label' => 'Employer Name', 'required' => false))->add('industry', 'text', array('attr' => array('class' => 'input-medium'), 'required' => false))->add('occupation', 'text', array('attr' => array('class' => 'input-medium'), 'required' => false))->add('businessType', 'text', array('attr' => array('class' => 'input-medium'), 'label' => 'Type of Business', 'required' => false))->add('employerAddress', 'text', array('attr' => array('class' => 'input-large'), 'label' => 'Employer Address', 'required' => false))->add('employmentCity', 'text', array('attr' => array('class' => 'input-medium'), 'label' => 'Employment City', 'required' => false))->add('employmentState', 'entity', array('attr' => array('class' => 'input-medium'), 'class' => 'WealthbotAdminBundle:State', 'label' => 'State', 'empty_value' => 'Select a State', 'required' => false))->add('employmentZip', 'text', array('attr' => array('class' => 'input-mini'), 'label' => 'Zip Code', 'required' => false));
     $builder->addEventListener(FormEvents::PRE_SET_DATA, array($this, 'onPreSetData'));
     $builder->addEventListener(FormEvents::BIND, array($this, 'onBindData'));
 }
 private function validateOwnerInformation(FormInterface $form, $data)
 {
     if ($form->has('first_name') && !$data->getFirstName()) {
         $form->get('first_name')->addError(new FormError('Required.'));
     }
     if ($form->has('middle_name') && !preg_match('/[A-Za-z]/', $data->getMiddleName())) {
         $form->get('middle_name')->addError(new FormError('Enter least 1 letter.'));
     }
     if ($form->has('last_name') && !$data->getLastName()) {
         $form->get('last_name')->addError(new FormError('Required.'));
     }
     if ($form->has('street') && !$data->getStreet()) {
         $form->get('street')->addError(new FormError('Required.'));
     }
     if ($form->has('city') && !$data->getCity()) {
         $form->get('city')->addError(new FormError('Required.'));
     }
     if ($form->has('state') && !$data->getState()) {
         $form->get('state')->addError(new FormError('Required.'));
     }
     if ($form->has('estimated_income_tax') && !$data->getEstimatedIncomeTax()) {
         $form->get('estimated_income_tax')->addError(new FormError('Required.'));
     }
     // Choices validation
     if ($form->has('marital_status') && !in_array($data->getMaritalStatus(), Profile::getMaritalStatusChoices())) {
         $form->get('marital_status')->addError(new FormError('Required.'));
     }
     if ($form->has('annual_income') && !in_array($data->getAnnualIncome(), Profile::getAnnualIncomeChoices())) {
         $form->get('annual_income')->addError(new FormError('Required.'));
     }
     if ($form->has('liquid_net_worth') && !in_array($data->getLiquidNetWorth(), array_keys(Profile::getLiquidNetWorthChoices()))) {
         $form->get('liquid_net_worth')->addError(new FormError('Required.'));
     }
     if ($form->has('employment_type') && !in_array($data->getEmploymentType(), array_keys(Profile::getEmploymentTypeChoices()))) {
         $form->get('employment_type')->addError(new FormError('Required.'));
     }
     if ($form->has('birth_date')) {
         $birthDateData = $form->get('birth_date')->getData();
         if ($birthDateData && $birthDateData instanceof \DateTime) {
             $year = (int) $birthDateData->format('Y');
             if ($year < 1900) {
                 $form->get('birth_date')->addError(new FormError('year must start with 19 or 20 e.g. 1980'));
             }
         } else {
             $form->get('birth_date')->addError(new FormError('date format must be MM-DD-YYYY'));
         }
     }
 }
 public function validate(FormEvent $event)
 {
     /** @var \Wealthbot\UserBundle\Entity\Profile $data */
     $data = $event->getData();
     $form = $event->getForm();
     if ($form->has('first_name') && !$data->getFirstName()) {
         $form->get('first_name')->addError(new FormError('Required.'));
     }
     if ($form->has('last_name') && !$data->getLastName()) {
         $form->get('last_name')->addError(new FormError('Required.'));
     }
     if ($form->has('street') && !$data->getStreet()) {
         $form->get('street')->addError(new FormError('Required.'));
     }
     if ($form->has('city') && !$data->getCity()) {
         $form->get('city')->addError(new FormError('Required.'));
     }
     if ($form->has('state') && !$data->getState()) {
         $form->get('state')->addError(new FormError('Required.'));
     }
     if ($form->has('estimated_income_tax') && !$data->getEstimatedIncomeTax()) {
         $form->get('estimated_income_tax')->addError(new FormError('Required.'));
     }
     // Choices validation
     if ($form->has('marital_status') && !in_array($data->getMaritalStatus(), Profile::getMaritalStatusChoices())) {
         $form->get('marital_status')->addError(new FormError('Required.'));
     }
     if ($form->has('annual_income') && !in_array($data->getAnnualIncome(), Profile::getAnnualIncomeChoices())) {
         $form->get('annual_income')->addError(new FormError('Required.'));
     }
     if ($form->has('liquid_net_worth') && !in_array($data->getLiquidNetWorth(), array_keys(Profile::getLiquidNetWorthChoices()))) {
         $form->get('liquid_net_worth')->addError(new FormError('Required.'));
     }
     if ($form->has('employment_type') && !in_array($data->getEmploymentType(), array_keys(Profile::getEmploymentTypeChoices()))) {
         $form->get('employment_type')->addError(new FormError('Required.'));
     }
     if ($form->has('birth_date')) {
         $birthDateData = $form->get('birth_date')->getData();
         if ($birthDateData && $birthDateData instanceof \DateTime) {
             $year = (int) $birthDateData->format('Y');
             if ($year < 1900) {
                 $form->get('birth_date')->addError(new FormError('year must start with 19 or 20 e.g. 1980'));
             }
         } else {
             $form->get('birth_date')->addError(new FormError('date format must be MM-DD-YYYY'));
         }
     }
     if ($form->has('spouse') && $data->getMaritalStatus() === Profile::CLIENT_MARITAL_STATUS_MARRIED) {
         /** @var ClientAdditionalContact $spouse */
         $spouse = $form->get('spouse')->getData();
         $phoneNum = str_replace(array(' ', '-', '(', ')'), '', $data->getPhoneNumber());
         $spouseValidator = new ClientSpouseFormValidator($form->get('spouse'), $data->getUser()->getSpouse());
         $spouseValidator->validate();
         $spouse->setSpouseFirstName($data->getFirstName());
         $spouse->setSpouseMiddleName($data->getMiddleName());
         $spouse->setSpouseLastName($data->getLastName());
         $spouse->setSpouseBirthDate($data->getBirthDate());
         $spouse->setState($data->getState());
         $spouse->setCity($data->getCity());
         $spouse->setStreet($data->getStreet());
         $spouse->setZip($data->getZip());
         $spouse->setPhoneNumber($phoneNum);
         $spouse->setType(ClientAdditionalContact::TYPE_SPOUSE);
         $spouse->setMaritalStatus(Profile::CLIENT_MARITAL_STATUS_MARRIED);
     }
 }
 protected function validateEmploymentType(FormInterface $form, $data)
 {
     if ($form->has('employment_type')) {
         $employmentType = $form->get('employment_type')->getData();
         if (!in_array($employmentType, array_keys(Profile::getEmploymentTypeChoices()))) {
             $form->get('employment_type')->addError(new FormError('Required.'));
         } else {
             if ($employmentType == Profile::CLIENT_EMPLOYMENT_TYPE_RETIRED || $employmentType == Profile::CLIENT_EMPLOYMENT_TYPE_UNEMPLOYED) {
                 $data->setEmployerName(null);
                 $data->setIndustry(null);
                 $data->setOccupation(null);
                 $data->setBusinessType(null);
                 $data->setEmployerAddress(null);
                 $data->setEmploymentCity(null);
                 $data->setEmploymentState(null);
                 /* if ($form->has('zipcode')) {
                        $data->setEmploymentZip(null);
                    }*/
                 if (!in_array($data->getIncomeSource(), PersonalInformation::getIncomeSourceChoices())) {
                     $form->get('income_source')->addError(new FormError('Required.'));
                 }
             } else {
                 $data->setIncomeSource(null);
                 $employerName = $data->getEmployerName();
                 $industry = $data->getIndustry();
                 $occupation = $data->getOccupation();
                 $businessType = $data->getBusinessType();
                 $employerAddress = $data->getEmployerAddress();
                 $city = $data->getEmploymentCity();
                 $state = $data->getEmploymentState();
                 if (is_null($employerName) || !is_string($employerName)) {
                     $form->get('employer_name')->addError(new FormError('Required.'));
                 }
                 if (is_null($industry) || !is_string($industry)) {
                     $form->get('industry')->addError(new FormError('Required.'));
                 }
                 if (is_null($occupation) || !is_string($occupation)) {
                     $form->get('occupation')->addError(new FormError('Required.'));
                 }
                 if (is_null($businessType) || !is_string($businessType)) {
                     $form->get('business_type')->addError(new FormError('Required.'));
                 }
                 if (is_null($employerAddress) || !is_string($employerAddress)) {
                     $form->get('employer_address')->addError(new FormError('Required.'));
                 }
                 if (is_null($city) || !is_string($city)) {
                     $form->get('employment_city')->addError(new FormError('Required.'));
                 }
                 if ($form->has('employment_state')) {
                     if (null === $state) {
                         $form->get('employment_state')->addError(new FormError('Required.'));
                     }
                 }
                 if ($form->has('employment_zip')) {
                     $zipDigits = 5;
                     $zip = str_replace(array(' ', '-'), '', $data->getEmploymentZip());
                     if (!is_numeric($zip)) {
                         $form->get('employment_zip')->addError(new FormError("Enter correct zip code."));
                     } elseif (strlen($zip) != $zipDigits) {
                         $form->get('employment_zip')->addError(new FormError("Zip code must be {$zipDigits} digits."));
                     } else {
                         $data->setEmploymentZip($zip);
                     }
                 }
             }
         }
     }
 }