public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $this->factory = $builder->getFormFactory();
     $builder->add('firstName', 'text', array('attr' => array('class' => 'input-medium'), 'label' => 'First Name', 'property_path' => 'profile.firstName'))->add('lastName', 'text', array('attr' => array('class' => 'input-medium'), 'label' => 'Last Name', 'property_path' => 'profile.lastName'))->add('middleName', 'text', array('attr' => array('class' => 'input-medium'), 'label' => 'Middle Name', 'property_path' => 'profile.middleName'))->add('birthDate', 'date', array('attr' => array('class' => 'jq-ce-date input-small'), 'format' => 'MM-dd-yyyy', 'label' => 'Birth Date', 'property_path' => 'profile.birthDate', 'widget' => 'single_text'))->add('citizenship', 'choice', array('expanded' => true, 'label' => 'U.S. citizen?', 'data' => 1, 'choices' => array('1' => 'Yes', '0' => 'No'), 'property_path' => false, 'constraints' => array(new True(array('message' => 'Your client should be U. S. citizen.')))));
     $builder->add('employmentStatus', 'choice', array('choices' => Profile::getEmploymentTypeChoices(), 'expanded' => true, 'label' => 'Employment Status', 'multiple' => false, 'property_path' => 'profile.employmentType', 'required' => true))->add('employerName', 'text', array('attr' => array('class' => 'input-small'), 'label' => 'Employer Name', 'property_path' => 'clientPersonalInformation.employerName', 'required' => false))->add('industry', 'text', array('attr' => array('class' => 'input-small'), 'property_path' => 'clientPersonalInformation.industry', 'required' => false))->add('occupation', 'text', array('attr' => array('class' => 'input-small'), 'property_path' => 'clientPersonalInformation.occupation', 'required' => false))->add('businessType', 'text', array('attr' => array('class' => 'input-small'), 'label' => 'Type of Business', 'property_path' => 'clientPersonalInformation.businessType', 'required' => false))->add('employerAddress', 'text', array('attr' => array('class' => 'input-medium'), 'label' => 'Employer Address', 'property_path' => 'clientPersonalInformation.employerAddress', 'required' => false))->add('employmentCity', 'text', array('attr' => array('class' => 'input-medium'), 'label' => 'Employment City', 'property_path' => 'clientPersonalInformation.city', 'required' => false))->add('employmentState', 'entity', array('attr' => array('class' => 'input-medium'), 'class' => 'WealthbotAdminBundle:State', 'label' => 'State', 'empty_value' => 'Select a State', 'property_path' => 'clientPersonalInformation.state', 'required' => false))->add('employmentZip', 'text', array('attr' => array('class' => 'input-mini'), 'label' => 'Zip Code', 'property_path' => 'clientPersonalInformation.zipcode', 'required' => false));
     $builder->add('maritalStatus', 'choice', array('attr' => array('class' => 'input-small'), 'choices' => Profile::getMaritalStatusChoices(), 'empty_value' => 'Choose an Option', 'label' => 'Marital Status', 'property_path' => 'profile.maritalStatus', '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 buildForm(FormBuilderInterface $builder, array $options)
 {
     parent::buildForm($builder, $options);
     $data = $builder->getData();
     $isExist = $data->getId();
     $builder->remove('citezen')->remove('ssn_tin_1')->remove('ssn_tin_2')->remove('ssn_tin_3')->remove('is_senior_political_figure')->remove('senior_spf_name')->remove('senior_political_title')->remove('senior_account_owner_relationship')->remove('senior_country_office')->remove('is_publicly_traded_company')->remove('publicle_company_name')->remove('publicle_address')->remove('publicle_city')->remove('publicleState')->remove('is_broker_security_exchange_person')->remove('broker_security_exchange_company_name')->remove('compliance_letter_file')->add('email', 'email')->add('first_name', 'text', array('required' => false, 'disabled' => true))->add('middle_name', 'text', array('required' => false, 'disabled' => true))->add('last_name', 'text', array('required' => false, 'disabled' => true))->add('birth_date', 'date', array('widget' => 'single_text', 'format' => 'MM-dd-yyyy', 'required' => true, 'disabled' => true, 'attr' => array('class' => 'jq-date input-small')))->add('citizenship', 'choice', array('choices' => array(1 => 'Yes', 0 => 'No'), 'expanded' => true, 'multiple' => false, 'required' => false, 'property_path' => false, 'data' => $isExist ? 1 : null, 'label' => $data && $data->getMaritalStatus() == 'Married' ? 'Are you and your spouse both U.S. citizens?' : 'Are you a U.S. citizen?', 'disabled' => true))->add('marital_status', 'choice', array('choices' => Profile::getMaritalStatusChoices(), 'empty_value' => 'Choose an Option', 'required' => false))->add('phone_number', 'text', array('required' => false))->add('spouse', new ClientSpouseFormType())->add('annual_income', 'choice', array('choices' => Profile::getAnnualIncomeChoices(), 'empty_value' => 'Choose an Option', 'required' => false))->add('estimated_income_tax', 'percent', array('precision' => 0, 'required' => false, 'label' => 'What is your estimated income tax bracket?'))->add('liquid_net_worth', 'choice', array('choices' => Profile::getLiquidNetWorthChoices(), 'empty_value' => 'Choose an Option', 'required' => false));
     $formFactory = $builder->getFormFactory();
     $builder->addEventListener(FormEvents::PRE_BIND, function (FormEvent $event) use($formFactory) {
         $form = $event->getForm();
         $data = $event->getData();
         if ($data === null) {
             return;
         }
         if (isset($data['marital_status'])) {
             $form->remove('citizenship');
             $form->add($formFactory->createNamed('citizenship', 'choice', null, array('choices' => array(1 => 'Yes', 0 => 'No'), 'expanded' => true, 'multiple' => false, 'required' => false, 'property_path' => false, 'data' => isset($data['id']) ? 1 : null, 'label' => $data['marital_status'] == 'Married' ? 'Are you and your spouse both U.S. citizens?' : 'Are you a U.S. citizen?', 'disabled' => true)));
         }
     });
     $builder->addEventListener(FormEvents::BIND, array($this, 'changeProfileValidate'));
 }
 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 validateMaritalStatus(FormInterface $form)
 {
     if ($form->has('marital_status')) {
         $maritalStatus = $form->get('marital_status')->getData();
         if (!in_array($maritalStatus, Profile::getMaritalStatusChoices())) {
             $form->get('marital_status')->addError(new FormError('Required.'));
         }
         if ($maritalStatus == Profile::CLIENT_MARITAL_STATUS_MARRIED) {
             if ($form->has('spouse_first_name')) {
                 $firstName = $form->get('spouse_first_name')->getData();
                 if (is_null($firstName) || !is_string($firstName)) {
                     $form->get('spouse_first_name')->addError(new FormError('Enter first name.'));
                 }
             }
             if ($form->has('spouse_last_name')) {
                 $firstName = $form->get('spouse_last_name')->getData();
                 if (is_null($firstName) || !is_string($firstName)) {
                     $form->get('spouse_last_name')->addError(new FormError('Enter last name.'));
                 }
             }
             if ($form->has('spouse_last_name')) {
                 $minYears = 18;
                 $birthDate = $form->get('spouse_birth_date')->getData();
                 if (!$birthDate) {
                     $form->get('spouse_birth_date')->addError(new FormError('Enter spouse date of birth.'));
                 } else {
                     $nowDate = new \DateTime('now');
                     $interval = $nowDate->diff($birthDate);
                     if ((int) $interval->format('%y%') < $minYears) {
                         $form->get('spouse_birth_date')->addError(new FormError("Your spouse must be at least {$minYears} years old."));
                     }
                 }
             }
         }
     }
 }