Liquid Snippets by ALSEL
📘 公式リファレンス📦 リファレンス/オブジェクト初級

form オブジェクト

Liquid テンプレート内でフォーム送信時の入力値やバリデーションエラーにアクセスするオブジェクト。contact フォーム、顧客登録、住所管理、記事コメントなど複数のフォーム種別に対応する。

用途
お問い合わせフォームや顧客アカウント関連フォーム送信時に、入力値の保持やエラーメッセージの表示、送信完了時のメッセージ出力をするとき。
設置場所
Liquid テンプレート内で `{{ form.errors }}` または `{{ form.email }}`、`{{ form.body }}` のようにプロパティを参照する。form オブジェクトは form タグブロック内で自動的に利用可能。
注意点
プロパティの可用性はフォーム種別によって異なる。例えば address1、address2、city、country などは customer_address フォーム専用であり、contact フォームでは使えない。errors プロパティが存在するとき nil 以外が返る。default_errors フィルターを errors に適用することで、ループ処理なしにデフォルトエラーメッセージを出力できる。
タグ:formvalidationerrorobject

仕様

341 行 / json
{
  "access": {
    "global": false,
    "parents": [],
    "template": []
  },
  "deprecated": false,
  "deprecation_reason": "",
  "description": "",
  "properties": [
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "If there are no errors, then `nil` is returned.\n\n> Tip:\n> You can apply the [`default_errors` filter](/docs/api/liquid/filters/default_errors) to `form.errors` to output default\n> error messages without having to loop through the array.",
      "examples": [],
      "return_type": [
        {
          "type": "form_errors",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "Any errors from the form.",
      "name": "errors"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "This property is exclusive to the [`customer_address` form](/docs/api/liquid/tags/form#form-customer_address).",
      "examples": [],
      "return_type": [
        {
          "type": "string",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The first address line associated with the address.",
      "name": "address1"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "This property is exclusive to the [`customer_address` form](/docs/api/liquid/tags/form#form-customer_address).",
      "examples": [],
      "return_type": [
        {
          "type": "string",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The second address line associated with the address.",
      "name": "address2"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "This property is exclusive to the [`new_comment` form](/docs/api/liquid/tags/form#form-new_comment).",
      "examples": [],
      "return_type": [
        {
          "type": "string",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The name of the author of the article comment.",
      "name": "author"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "This property is exclusive to the [`contact`](/docs/api/liquid/tags/form#form-contact) and [`new_comment`](/docs/api/liquid/tags/form#form-new_comment)\nforms.",
      "examples": [],
      "return_type": [
        {
          "type": "string",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The content of the contact submission or article comment.",
      "name": "body"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "This property is exclusive to the [`customer_address` form](/docs/api/liquid/tags/form#form-customer_address).",
      "examples": [],
      "return_type": [
        {
          "type": "string",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The city associated with the address.",
      "name": "city"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "This property is exclusive to the [`customer_address` form](/docs/api/liquid/tags/form#form-customer_address).",
      "examples": [],
      "return_type": [
        {
          "type": "string",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The company associated with the address.",
      "name": "company"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "This property is exclusive to the [`customer_address` form](/docs/api/liquid/tags/form#form-customer_address).",
      "examples": [],
      "return_type": [
        {
          "type": "string",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The country associated with the address.",
      "name": "country"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "This property is exclusive to the following forms:\n\n- [`contact`](/docs/api/liquid/tags/form#form-contact)\n- [`create_customer`](/docs/api/liquid/tags/form#form-create_customer)\n- [`customer`](/docs/api/liquid/tags/form#form-customer)\n- [`customer_login`](/docs/api/liquid/tags/form#form-customer_login)\n- [`new_comment`](/docs/api/liquid/tags/form#form-new_comment)\n- [`recover_customer_password`](/docs/api/liquid/tags/form#form-recover_customer_password)\n- [`product`](/docs/api/liquid/tags/form#form-product)",
      "examples": [],
      "return_type": [
        {
          "type": "string",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The email associated with the form.",
      "name": "email"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "This property is exclusive to the [`create_customer`](/docs/api/liquid/tags/form#form-create_customer) and\n[`customer_address`](/docs/api/liquid/tags/form#form-customer_address) forms.",
      "examples": [],
      "return_type": [
        {
          "type": "string",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The first name associated with the customer or address.",
      "name": "first_name"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "",
      "examples": [],
      "return_type": [
        {
          "type": "string",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The ID of the form.",
      "name": "id"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "This property is exclusive to the [`create_customer`](/docs/api/liquid/tags/form#form-create_customer) and\n[`customer_address`](/docs/api/liquid/tags/form#form-customer_address) forms.",
      "examples": [],
      "return_type": [
        {
          "type": "string",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The last name associated with the customer or address.",
      "name": "last_name"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "This property is exclusive to the [`customer_login` form](/docs/api/liquid/tags/form#form-customer_login).",
      "examples": [],
      "return_type": [
        {
          "type": "boolean",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "Returns `true`.",
      "name": "password_needed"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "This property is exclusive to the [`customer_address` form](/docs/api/liquid/tags/form#form-customer_address).",
      "examples": [],
      "return_type": [
        {
          "type": "string",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The phone number associated with the address.",
      "name": "phone"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "> Note:\n> The [`customer_address` form](/docs/api/liquid/tags/form#form-customer_address) always returns `true`.",
      "examples": [],
      "return_type": [
        {
          "type": "boolean",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "Returns `true` if the form was submitted successfully. Returns `false` if there were errors.",
      "name": "posted_successfully?"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "This property is exclusive to the [`customer_address` form](/docs/api/liquid/tags/form#form-customer_address).",
      "examples": [],
      "return_type": [
        {
          "type": "string",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The province associated with the address.",
      "name": "province"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "This property is exclusive to the [`customer_address` form](/docs/api/liquid/tags/form#form-customer_address).",
      "examples": [],
      "return_type": [
        {
          "type": "string",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "Renders an HTML checkbox that can submit the address as the customer's default address.",
      "name": "set_as_default_checkbox"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "This property is exclusive to the [`product` form](/docs/api/liquid/tags/form#form-product).",
      "examples": [],
      "return_type": [
        {
          "type": "string",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The nickname of the gift card recipient.",
      "name": "name"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "This property is exclusive to the [`product` form](/docs/api/liquid/tags/form#form-product).",
      "examples": [],
      "return_type": [
        {
          "type": "string",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The personalized message intended for the recipient.",
      "name": "message"
    },
    {
      "deprecated": false,
      "deprecation_reason": "",
      "description": "This property is exclusive to the [`customer_address` form](/docs/api/liquid/tags/form#form-customer_address).",
      "examples": [],
      "return_type": [
        {
          "type": "string",
          "name": "",
          "description": "",
          "array_value": ""
        }
      ],
      "summary": "The zip or postal code associated with the address.",
      "name": "zip"
    }
  ],
  "summary": "Information about a form created by a [`form` tag](/docs/api/liquid/tags/form).",
  "name": "form",
  "examples": [],
  "json_data": {
    "path": "",
    "handle": "",
    "data_from_file": "{\"address1\":\"12 Phoenix Feather Alley\",\"address2\":\"1\",\"author\":null,\"body\":null,\"city\":\"Calgary\",\"company\":null,\"country\":\"Canada\",\"email\":null,\"errors\":null,\"first_name\":\"Cornelius\",\"id\":\"new\",\"last_name\":\"Potionmaker\",\"password_needed?\":false,\"phone\":\"44 131 496 0905\",\"posted_successfully?\":true,\"province\":\"Alberta\",\"set_as_default_checkbox\":\"<input type='checkbox' id='address_default_address_new' name='address[default]' value='1'>\",\"zip\":\"T1X 0L4\"}"
  },
  "return_type": []
}

出典・ライセンス

License:
MIT

このコードは Shopify 著作の MIT ライセンスソースです。 原本の著作権は Shopify が保有します。日本語訳は ALSEL によるものです。

関連項目

📘 公式リファレンス📦 リファレンス/オブジェクト初級

content_for_header オブジェクト

Shopify が必要とするスクリプト(分析・チェックアウト・言語設定など)をすべて動的に出力するオブジェクト。theme.liquid の <head> タグ内に埋め込む必須要素。

📁 theme-liquid-docs·MIT·20
📘 公式リファレンス📦 リファレンス/オブジェクト中級

metaobjects オブジェクト

ストア全体のメタオブジェクト定義にアクセスするグローバルオブジェクト。個別のメタオブジェクトはタイプとハンドルで参照でき、メタオブジェクト定義のエントリをループで反復処理できる。

📁 theme-liquid-docs·MIT·20
📘 公式リファレンス📦 リファレンス/オブジェクト初級

additional_checkout_buttons オブジェクト

PayPal Express Checkout など、オフサイト決済に対応した外部決済プロバイダーがストアに設定されているかを真偽値で返す。`content_for_additional_checkout_buttons` と組み合わせて、該当するチェックアウトボタンを条件付きで表示する。

📁 theme-liquid-docs·MIT·27
📘 公式リファレンス📦 リファレンス/オブジェクト初級

canonical_url オブジェクト

現在のページの正規 URL を取得するオブジェクト。Google などの検索エンジンに対してどのページ版が正規であるかを指定するために使用する。

📁 theme-liquid-docs·MIT·27
📘 公式リファレンス📦 リファレンス/オブジェクト初級

content_for_index オブジェクト

ホームページに表示するセクションの内容を動的に返すオブジェクト。Liquid インデックステンプレートで必ず使用する。

📁 theme-liquid-docs·MIT·27
📘 公式リファレンス📦 リファレンス/オブジェクト初級

content_for_additional_checkout_buttons オブジェクト

PayPal、Apple Pay、Google Pay など複数の決済プロバイダが有効になっているとき、その決済ボタンを HTML として出力するオブジェクト。`additional_checkout_buttons` で有無を判定したうえで、このオブジェクトで実際のボタンを表示する。

📁 theme-liquid-docs·MIT·27