首页 文章

Sf2:Fos UserBundle注册表单,单字段密码

提问于
浏览
1

我想有一个字段密码而不是“重复”类型的字段 .

我用这种方式覆盖了RegistrationFormType .

public function buildForm(FormBuilderInterface $builder, array $options)
{
    parent::buildForm($builder, $options);
    $builder
        ->remove('username')  // email is used as username
        ->remove('plainPassword') // use only a single field password
        ->add('firstname')
        ->add('lastname')
        ->add('plainPassword', 'password');
}

并在我的树枝模板中以这种方式调用它

{{ form_widget(form.plainPassword, {'attr': {'class': 'input', 'placeholder': 'Password', 'required': 'required'}}) }}

只要在表单构建器中添加字段plainPassword,它就会返回:

在第38行的vendor / symfony / symfony / src / Symfony / Component / Validator / Constraints / LengthValidator.php中给出的类型“string”,“array”的预期参数

我究竟做错了什么?我找不到有关覆盖此字段的任何主题 .

UPDATE :

dump($builder->all());

回报:

array:4 [▼
"email" => FormBuilder {#1037 ▶}
"firstname" => FormBuilder {#1046 ▶}
"lastname" => FormBuilder {#1196 ▶}
"plainPassword" => FormBuilder {#1184 ▼
-children: []
-unresolvedChildren: []
#locked: false
-dispatcher: EventDispatcher {#1183 ▶}
-name: "plainPassword"
-propertyPath: null
-mapped: true
-byReference: true
-inheritData: false
-compound: false
-type: ResolvedTypeDataCollectorProxy {#1191 ▶}
-viewTransformers: []
-modelTransformers: []
-dataMapper: null
-required: true
-disabled: false
-errorBubbling: false
-emptyData: Closure {#1185 ▶}
-attributes: array:5 [▶]
-data: null
-dataClass: null
-dataLocked: false
-formFactory: FormFactory {#429 ▶}
-action: ""
-method: "POST"
-requestHandler: HttpFoundationRequestHandler {#987 ▶}
-autoInitialize: true
-options: array:49 [▼
  "block_name" => null
  "disabled" => false
  "label" => null
  "label_format" => null
  "translation_domain" => null
  "auto_initialize" => true
  "trim" => false
  "required" => true
  "read_only" => false
  "max_length" => null
  "pattern" => null
  "property_path" => null
  "mapped" => true
  "by_reference" => true
  "virtual" => null
  "compound" => false
  "method" => "POST"
  "action" => ""
  "post_max_size_message" => "The uploaded file was too large. Please try to upload a smaller file."
  "error_mapping" => []
  "cascade_validation" => false
  "invalid_message" => "This value is not valid."
  "invalid_message_parameters" => []
  "allow_extra_fields" => false
  "extra_fields_message" => "This form should not contain extra fields."
  "csrf_protection" => true
  "csrf_field_name" => "_token"
  "csrf_message" => "The CSRF token is invalid. Please try to resubmit the form."
  "csrf_provider" => CsrfTokenManager {#534 ▶}
  "intention" => null
  "sonata_admin" => null
  "sonata_field_description" => null
  "label_render" => true
  "sonata_help" => null
  "horizontal_label_class" => ""
  "horizontal_label_offset_class" => ""
  "horizontal_input_wrapper_class" => ""
  "description" => ""
  "always_empty" => true
  "attr" => []
  "data_class" => null
  "empty_data" => Closure {#1185 ▶}
  "error_bubbling" => false
  "label_attr" => []
  "inherit_data" => false
  "validation_groups" => null
  "constraints" => []
  "csrf_token_manager" => CsrfTokenManager {#534 ▶}
  "csrf_token_id" => null
]
}
]

1 回答

  • 0

    我将FOS用户包从1.3.6更新到2.0.0-alpha3(出于不同的原因) . 它修复了错误 .

相关问题