2017-06-06 41 views
0

如何使用FOSRest提交RepeatedType?使用RepeatedType和FOSRest的Symfony 3表格

我加入以下formtype:

/** 
* {@inheritdoc} 
*/ 
public function buildForm(FormBuilderInterface $builder, array $options) 
{ 
    $builder->add('email', TextType::class); 
    $builder->add('firstName', TextType::class); 
    $builder->add('lastName', TextType::class); 
    $builder->add('password', RepeatedType::class, [ 
     'type' => PasswordType::class, 
     'invalid_message' => 'The password fields must match.', 
     'required' => true 
    ]); 
} 

這是我提交的數據:

array(1) { 
["user"]=> 
array(4) { 
    ["email"]=> 
    string(21) "[email protected]" 
    ["firstName"]=> 
    string(4) "Test" 
    ["lastName"]=> 
    string(9) "User" 
    ["password"]=> 
    array(2) { 
      ["first"]=> 
      string(8) "password" 
      ["second"]=> 
      string(8) "password" 
    } 
    } 
} 

一切正常,除了repeatedType拋出:這種形式不應包含額外的字段。

什麼是提交給重複類型的正確格式?該文檔是不是這是很清楚......

謝謝

回答

0

嘗試改變這一點:

$builder->add('password', RepeatedType::class, [ 
    'type' => PasswordType::class, 
    'invalid_message' => 'The password fields must match.', 
    'required' => true 
]); 

這樣:

$builder->add('password', RepeatedType::class, [ 
    'type' => PasswordType::class, 
    'first_options' => array('label' => 'Password'), 
    'second_options' => array('label' => 'Repeat Password') 
]);