使用带有FOSRest的

时间:2017-06-06 09:52:46

标签: forms symfony

如何使用FOSRest提交RepeatedType?

我添加了以下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) "Testuser@test.be"
    ["firstName"]=>
    string(4) "Test"
    ["lastName"]=>
    string(9) "User"
    ["password"]=>
    array(2) {
          ["first"]=>
          string(8) "password"
          ["second"]=>
          string(8) "password"
    }
  }
}

除了重复类型抛出之外,一切正常:此表单不应包含额外的字段。

提交到repeatedType的正确格式是什么?文档在这方面并不是很清楚......

谢谢

1 个答案:

答案 0 :(得分: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')
]);