Skip to content

[翻訳]reference/forms/types/form.rst #306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 96 additions & 12 deletions reference/forms/types/form.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,127 @@

.. note::

* 対象バージョン:2.3
* 翻訳更新日:2013/11/24
* 対象バージョン:2.3+
* 翻訳更新日:2014/06/20

form フィールドタイプ
=====================

:class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\FormType` を参照してください。

``form`` タイプはすべてのフィールドで利用可能となるいくつかのオプションをあらかじめ定義します。
``form`` タイプを親タイプにもつすべてのタイプで利用可能なオプションを事前にいくつか定義しています。

+-----------+--------------------------------------------------------------------+
|オプション | - `data`_ |
| | - `data_class`_ |
| | - `empty_data`_ |
| | - `compound`_ |
| | - `required`_ |
| | - `label_attr`_ |
| | - `constraints`_ |
| | - `cascade_validation`_ |
| | - `read_only`_ |
| | - `trim`_ |
| | - `mapped`_ |
| | - `property_path`_ |
| | - `max_length`_ (2.5 で非推奨) |
| | - `by_reference`_ |
| | - `error_bubbling`_ |
| | - `inherit_data`_ |
| | - `error_mapping`_ |
| | - `invalid_message`_ |
| | - `invalid_message_parameters`_ |
| | - `extra_fields_message`_ |
| | - `post_max_size_message`_ |
| | - `pattern`_ (2.5 で非推奨) |
| | - `action`_ |
| | - `method`_ |
+-----------+--------------------------------------------------------------------+
| 継承された| - `block_name`_ |
| オプション| - `disabled`_ |
| | - `label`_ |
| | - `attr`_ |
| | - `translation_domain`_ |
| | - `auto_initialize`_ |
+-----------+--------------------------------------------------------------------+
| 親クラス | none |
+-----------+--------------------------------------------------------------------+
| クラス | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\FormType` |
+-----------+--------------------------------------------------------------------+

フィールドオプション
--------------------

.. include:: /reference/forms/types/options/data.rst.inc

.. include:: /reference/forms/types/options/data_class.rst.inc

.. include:: /reference/forms/types/options/empty_data.rst.inc

.. include:: /reference/forms/types/options/compound.rst.inc

.. _reference-form-option-required:

.. include:: /reference/forms/types/options/required.rst.inc

.. include:: /reference/forms/types/options/label_attr.rst.inc

.. include:: /reference/forms/types/options/constraints.rst.inc

.. include:: /reference/forms/types/options/cascade_validation.rst.inc

.. include:: /reference/forms/types/options/read_only.rst.inc

.. include:: /reference/forms/types/options/disabled.rst.inc

.. include:: /reference/forms/types/options/trim.rst.inc

.. include:: /reference/forms/types/options/mapped.rst.inc

.. include:: /reference/forms/types/options/property_path.rst.inc

.. include:: /reference/forms/types/options/attr.rst.inc
.. _reference-form-option-max_length:

.. include:: /reference/forms/types/options/translation_domain.rst.inc
.. include:: /reference/forms/types/options/max_length.rst.inc

.. include:: /reference/forms/types/options/by_reference.rst.inc

.. include:: /reference/forms/types/options/error_bubbling.rst.inc

.. include:: /reference/forms/types/options/inherit_data.rst.inc

.. include:: /reference/forms/types/options/error_mapping.rst.inc

.. include:: /reference/forms/types/options/invalid_message.rst.inc

.. include:: /reference/forms/types/options/invalid_message_parameters.rst.inc

.. include:: /reference/forms/types/options/extra_fields_message.rst.inc

.. include:: /reference/forms/types/options/post_max_size_message.rst.inc

.. _reference-form-option-pattern:

.. include:: /reference/forms/types/options/pattern.rst.inc

.. include:: /reference/forms/types/options/action.rst.inc

.. include:: /reference/forms/types/options/method.rst.inc

継承されたオプション
--------------------

以下のオプションは :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\BaseType` クラスで定義されています。
``BaseType`` クラスは ``form`` タイプと :doc:`button type </reference/forms/types/button>` の両方の親クラスですが、フォームタイプツリーの一部ではありません(すなわち、それ自身はフォームタイプとして利用できません)。

.. include:: /reference/forms/types/options/block_name.rst.inc

inherit_data
------------
.. include:: /reference/forms/types/options/disabled.rst.inc

.. include:: /reference/forms/types/options/label.rst.inc

.. include:: /reference/forms/types/options/attr.rst.inc

.. include:: /reference/forms/types/options/translation_domain.rst.inc

.. include:: /reference/forms/types/options/auto_initialize.rst.inc

:doc:`/cookbook/form/inherit_data_option` を参照してください。

.. 2013/11/24 yositani2002 b675661199d466be4b6cb6f70d16aa1e3574c789
.. 2014/06/20 yositani2002 21a4b9df8f4819b73ced858f323e835e10dfd89c
13 changes: 13 additions & 0 deletions reference/forms/types/options/action.rst.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
action
~~~~~~

.. versionadded:: 2.3
``action`` オプションは Symfony 2.3 から追加されました。

**データ型**: ``string`` **デフォルト**: empty string

このオプションは、どこにフォームのデータを送信するかを指定します(通常はURI)。
その値は ``form`` 要素の ``action`` 属性としてレンダリングされます。
空の値は、同じドキュメント参照と見なされます。つまり、フォームは、レンダリングしたフォームと同じURIに送信されます。

.. 2014/06/20 yositani2002 72c30c2fa1af40af7a1f3e672005d360a898ca07
10 changes: 10 additions & 0 deletions reference/forms/types/options/auto_initialize.rst.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
auto_initialize
~~~~~~~~~~~~~~~

**データ型**: ``boolean`` **デフォルト**: ``true``

内部オプション:フォームを自動的に初期化されるべきかどうかを設定します。
このオプションはすべてのフィールドでルートフォームに対しては ``true`` のみであるべきです。
このオプションを変更する必要はありませんし、おそらくそれを心配する必要もありません。

.. 2014/06/20 yositani2002 58170fe71fcf76ad59047caf629357d61e41a6c3
10 changes: 10 additions & 0 deletions reference/forms/types/options/compound.rst.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
compound
~~~~~~~~

**データ型**: ``boolean`` **デフォルト**: ``true``

フォームが合成物である場合は、このオプションが指定されます。
これは、フォームが実際に子要素を持っているかどうかとは無関係です。
フォームが合成物である時は子要素をまったく持つことができません(例えば、空のコレクション型)。

.. 2014/06/20 yositani2002 f6a65660b5c329c99979efa26011324f02b98628
15 changes: 15 additions & 0 deletions reference/forms/types/options/data_class.rst.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
data_class
~~~~~~~~~~

**データ型**: ``string``

このオプションは、フォームで使用する適切なデータ·マッパーを設定するために使われます。
オブジェクトを必要とする任意のフィールドタイプに使用することができます。

.. code-block:: php

$builder->add('media', 'sonata_media_type', array(
'data_class' => 'Acme\DemoBundle\Entity\Media',
));

.. 2014/06/20 yositani2002 69a2ed1f816c209e477ea3560782f5a208c6f0a6
9 changes: 0 additions & 9 deletions reference/forms/types/options/data_timezone.rst.inc

This file was deleted.

14 changes: 0 additions & 14 deletions reference/forms/types/options/date_pattern.rst.inc

This file was deleted.

9 changes: 9 additions & 0 deletions reference/forms/types/options/extra_fields_message.rst.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
extra_fields_message
~~~~~~~~~~~~~~~~~~~~

**データ型**: ``string`` **デフォルト**: ``This form should not contain extra fields.``

これは検証エラーメッセージです。送信されたフォームデータに、フォーム定義の一部ではないフィールドが1つ以上含まれている場合に使われます。
プレースホルダ ``{{extra_fields}}`` は、送信された余分なフィールド名を、カンマ区切りのリストで表示することができます。

.. 2014/06/20 yositani2002 dd6c0a765cc7ab3a93363f48ad59fac67bee82cb
37 changes: 37 additions & 0 deletions reference/forms/types/options/method.rst.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
method
~~~~~~

.. versionadded:: 2.3
``method`` オプションは Symfony 2.3 から追加されました。

**データ型**: ``string`` **デフォルト**: ``POST``

このオプションでは、フォームのデータを送信するために使用されるHTTPメソッドを指定します。
その値は ``form`` 要素の ``method`` 属性として表示されます。
また、 ``handleRequest()`` メソッドの中で送信後、フォームの送信を処理するかどうかを決定するために使用されています。
可能な値は次のとおりです。
This option specifies the HTTP method used to submit the form's data. Its
value is rendered as the ``method`` attribute of the ``form`` element and is
used to decide whether to process the form submission in the
``handleRequest()`` method after submission. Possible values are:

* POST
* GET
* PUT
* DELETE
* PATCH

.. note:

メソッドが PUT 、PATCH 、または DELETE の時、 Symfony は自動的にフォームに hidden フィールド ``_method`` をレンダリングします。
これらは、"偽" のHTTPメソッドとして使用され、標準的なブラウザではサポートされていません。
詳細については、以下を参照してください。
:doc:`/cookbook/routing/method_parameters`

.. note:

PATCH メソッドは部分データを送信することができます。
言い換えれば、送信されたフォームデータの特定フィールドが欠落している場合、それらは無視され、デフォルト値が(もしあれば)使用されます。
他のすべてのHTTPメソッドは、いくつかのフィールドが欠落している場合、それらのフィールドには ``null`` が設定されます。

.. 2014/06/20 yositani2002 72c30c2fa1af40af7a1f3e672005d360a898ca07
21 changes: 21 additions & 0 deletions reference/forms/types/options/pattern.rst.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.. caution::

``pattern`` オプションは非推奨となり、3.0で削除されます。
その代わりに、``attr`` オプションに ``pattern`` キーを持つ配列を設定し使用して下さい。

pattern
~~~~~~~

**データ型**: ``string`` **デフォルト**: ``null``

これは HTML5 ``pattern`` 属性に指定した正規表現によるフィールド入力の制限を追加します。

.. caution:

``pattern`` 属性は利便性のためのみでクライアント側の検証を提供します。信頼性の高いサーバー側の検証の代替品として使用してはいけません。

.. note:

検証制約を使用する場合、このオプションは、サーバー側の検証と一致するように自動的にいくつかの制約を設定します。

.. 2014/06/20 yositani2002 456da2802373c6a6be0f719210ee791c5cf9e3ed
13 changes: 13 additions & 0 deletions reference/forms/types/options/post_max_size_message.rst.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
post_max_size_message
~~~~~~~~~~~~~~~~~~~~~

**データ型**: ``string`` **デフォルト**: ``The uploaded file was too large. Please try to upload a smaller file.``

これは送信されたPOSTデータが ``php.ini`` の ``post_max_size`` ディレクティブを超えた場合に使われる検証エラーメッセージです。
``{{ max }}`` プレースホルダは、許可されたサイズを表示するために使用することができます。

.. note:

``post_max_size`` の検証はルートフォームのみ発生します。

.. 2014/06/20 yositani2002 d066f4d9e7518462c837d846a59bc5b8fc1ffcd9
18 changes: 12 additions & 6 deletions reference/forms/types/options/property_path.rst.inc
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
* ``property_path`` [type: any, default: the field's value]
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.
property_path
~~~~~~~~~~~~~

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.
**データ型**: ``any`` **デフォルト**: ``the field's name``

フィールドには、デフォルトで、フォームのドメインオブジェクトのプロパティの値を表示します。フォームの送信時に、送信された値はオブジェクトに書き込まれます。

フィールドの読み取りと書き込みのプロパティを上書きしたい場合は、 ``property_path`` オプションを設定することでできます。そのデフォルト値は、フィールドの名前です。

オブジェクトの読み込み、書き込み時にそのフィールドを無視したい場合は、\ ``property_path`` オプションを ``false`` にすることで出来ます。しかし、その目的での ``property_path`` の使用は推奨されません。
``mapped`` オプションを使用する必要があります。

.. 2014/06/20 yositani2002 6f286e18acdf003e2f1ced45b202b2578a4a47a6
9 changes: 0 additions & 9 deletions reference/forms/types/options/user_timezone.rst.inc

This file was deleted.