概述 快速入门 教程 手册 最佳实践 组件 参考 贡献

发布于 2015-08-27 16:49:08 | 139 次阅读 | 评论: 0 | 来源: 网络整理

The hidden type represents a hidden input field.

Rendered as input hidden field
Overriden options
Inherited options
Parent type form
Class HiddenType

Overridden Options

error_bubbling

default: true

Pass errors to the root form, otherwise they will not be visible.

required

default: false

Hidden fields cannot have a required attribute.

Inherited Options

These options inherit from the form type:

data

type: mixed default: Defaults to field of the underlying object (if there is one)

When you create a form, each field initially displays the value of the corresponding property of the form’s domain object (if an object is bound to the form). If you want to override the initial value for the form or just an individual field, you can set it in the data option:

$builder->add('token', 'hidden', array(
    'data' => 'abcdef',
));

注解

The default values for form fields are taken directly from the underlying data structure (e.g. an entity or an array). The data option overrides this default value.

error_mapping

type: array default: empty

This option allows you to modify the target of a validation error.

Imagine you have a custom method named matchingCityAndZipCode that validates whether the city and zip code match. Unfortunately, there is no “matchingCityAndZipCode” field in your form, so all that Symfony can do is display the error on top of the form.

With customized error mapping, you can do better: map the error to the city field so that it displays above it:

public function configureOptions(OptionsResolver $resolver)
{
    $resolver->setDefaults(array(
        'error_mapping' => array(
            'matchingCityAndZipCode' => 'city',
        ),
    ));
}

Here are the rules for the left and the right side of the mapping:

  • The left side contains property paths;
  • If the violation is generated on a property or method of a class, its path is simply propertyName;
  • If the violation is generated on an entry of an array or ArrayAccess object, the property path is [indexName];
  • You can construct nested property paths by concatenating them, separating properties by dots. For example: addresses[work].matchingCityAndZipCode;
  • The left side of the error mapping also accepts a dot ., which refers to the field itself. That means that any error added to the field is added to the given nested field instead;
  • The right side contains simply the names of fields in the form.

mapped

type: boolean default: true

If you wish the field to be ignored when reading or writing to the object, you can set the mapped option to false.

property_path

type: any default: the field's name

Fields display a property value of the form’s domain object by default. When the form is submitted, the submitted value is written back into the object.

If you want to override the property that a field reads from and writes to, you can set the property_path option. Its default value is the field’s name.

If you wish the field to be ignored when reading or writing to the object you can set the property_path option to false, but using property_path for this purpose is deprecated, you should use the mapped option.

最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务