2015-05-15 103 views
0

我試圖用Symfony2 formbuilder創建一個註冊表單。這是我第一次,我有一些問題。我如何根據國家輸入顯示所有城市和州?例如,如果我選擇英國,我想要得到英國的所有州,並且在州內的所有城市之後......這是如何實現的?我只在表單文檔中找到了國家選項,其中顯示了所有國家......但如何處理州和城市?Symfony2根據輸入顯示國家和城市

這是形式:

public function registerAction() 
    { 
      $em = $this->getDoctrine()->getManager(); 
      $products = $em->getRepository('MpShopBundle:Product')->findAll(); 

      $form = $this->createFormBuilder() 
       ->add('title', 'choice', array(
       'choices' => array('-' => '-', 'mr' => 'Mr.', 'mrs' => 'Mrs.', 'mss' => 'Miss.'))) 
       ->add('firstname', 'text') 
       ->add('lastname', 'text') 
       ->add('Email', 'email') 
       ->add('Password', 'password') 
       ->add('DateOfBirth', 'date') 
       ->add('Company', 'text') 
       ->add('Adress', 'text') 
       ->add('Country', 'country') 
       ->add('State', 'locale')  
       ->add('City', 'text') 
       ->add('ZipPostalCode', 'text') 
       ->add('AdditionalInformation', 'textarea') 
       ->add('HomePhone', 'number') 
       ->add('MobilePhone', 'number') 
       ->getForm() 

       ; 
       return $this->render('MpShopBundle:Frontend:registration.html.twig', array(
       'products'=>$products, 
       'form'=>$form->createView(),  
       )); 

    } 

我能做些什麼>?

回答