説明
について wpforms_display_field_after
アクションはフォームが表示される前に発生し、ラベルなどの特定のフォーム要素の位置を決定します。
パラメータ
- フィールド
- (配列) サニタイズされたエントリーフィールドの値/プロパティ。
- フォームデータ
- (配列) フォームの設定/データ。
ソース
wpforms/src/Frontend/Frontend.php
詳細情報
このアクションはフォームが表示される前に実行されます。このアクションは、フォームフィールドのラベルなど、フォームの属性を移動させるために使うことができます。
例
注意すべき点は、このアクションを使ってフィールドラベルをフォームフィールドの下に再配置する場合、最初に wpforms_display_field_before
アクションを呼び出して、フォームフィールドの後にラベルを再配置できるようにします。
/** * Action fires before the form is displayed to determine position of certain form elements such as labels. * * @link https://wpforms.com/developers/wpforms_display_field_after/ * * @param array $fields Sanitized entry field values/properties. * @param array $form_data Form settings/data. * @return array */ /* First remove the label from appearing above the form field for form 1289 */ function wpf_dev_display_field_before( $field, $form_data ) { if ( absint( $form_data[ 'id' ] ) !== 1289 ) { return; } remove_action( 'wpforms_display_field_before', array( wpforms()->frontend, 'field_label' ), 15 ); } add_action( 'wpforms_display_field_before', 'wpf_dev_display_field_before', 10, 2 ); /* Now position the label to appear below the form field for form 1289 */ function wpf_dev_display_field_after( $field, $form_data ) { if ( absint( $form_data[ 'id' ] ) !== 1289 ) { return; } wpforms()->frontend->field_label( $field, $form_data ); } add_action( 'wpforms_display_field_after', 'wpf_dev_display_field_after', 1, 2 );
参考記事
- CSSを使ってフォームフィールドにマテリアルデザインを追加する方法
- フローティングラベル付きフォームの作り方
- CSSを使ってフォームフィールドにマテリアルデザインを追加する方法
- 保存と再開アドオンと改ページの使い方