07 フォームとバリデータ

□未翻訳

□翻訳中

□翻訳完了(細田謙二)

■レビュー(Omi Chiba)

フォームとバリデータ

web2pyでフォームを構築するには以下の4通りの方法があります:

There are four distinct ways to build forms in web2py:

  • FORM はHTMLヘルパに関して低レベルの実装を提供します。FORMオブジェクトはHTMLへとシリアライズすることができ、そこに含まれるフィールドについて把握しています。FORMオブジェクトは送信フォームの値を検証することができます。

  • provides a low-level implementation in terms of HTML helpers. A FORM object can be serialized into HTML and is aware of the fields it contains. A FORM object knows how to validate submitted form values.

  • SQLFORM は、作成、更新、削除のフォームを、既存のデータベーステーブルから構築するための高レベルのAPIを提供します。

  • provides a high-level API for building create, update and delete forms from an existing database table.

  • SQLFORM.factory はSQLFORMの上にある抽象化レイヤです。データベースが用意されてない場合でもフォーム生成機能を活用できるようにしています。これは、テーブルの記述からSQLFORMととても良く似たフォームを生成します。ただしデータベース・テーブルを作成する必要はありません。

  • is an abstraction layer on top of SQLFORM in order to take advantage of the form generation features even if there is no database present. It generates a form very similar to SQLFORM from the description of a table but without the need to create the database table.

  • CRUD メソッド。SQLFORMと同等でSQLFORMに基づく関数が用意されていますが、よりコンパクトな表記が可能になります。

  • methods. These are functionally equivalent to SQLFORM and are based on SQLFORM, but provide a more compact notation.

これらすべてのフォームは自分自身を把握しており、入力が検証を通らなかった場合、自分自身を修正してエラーメッセージを加えることができます。フォームでは、検証によって生成された検証済み変数とエラーメッセージを問い合わせることができます。

All these forms are self-aware and, if the input does not pass validation, they can modify themselves and add error messages. The forms can be queried for the validated variables and for error messages that have been generated by validation.

任意のHTMLコードは、ヘルパを用いて、フォームへ挿入、また、フォームから抽出することができます。

Arbitrary HTML code can be inserted into or extracted from the form using helpers.