Formヘルパーで出力したタグに備考を記載する
Formヘルパーのinputメソッドを使うと、labelで括られた項目名と、入力フォームが自動的に出力されますが、
そこに「 * 必須」とか「6文字以上12文字以下」のように付記を入れる方法。
$options[‘before’], $options[‘between’], $options[‘after’]のいずれかを指定する。
基本的な使い方は、上記の記事ままですが、
$options[‘after’]に入力した内容は、特に何のタグでも括られずに出力されています。
echo $form->input('username', array( 'label' => __('UserId', true), 'maxlength' => $idLength['max'], 'after' => sprintf(__('Between %d to %d characters', true), $idLength['min'], $idLength['max']), ) );
↓
<div class="input text"> <label for="UserUsername">UserId</label> <input name="data[User][username]" maxlength="12" value="" id="UserUsername" type="text"> Between 4 to 12 characters </div>
必要がある場合は適宜、$htmlヘルパー等使ってタグでくくった文字列を、$options[‘after’]等に指定すること。
例
echo $form->input('username', array( 'label' => __('UserId', true), 'maxlength' => $idLength['max'], 'after' => $html->tag( 'div', sprintf(__('Between %d to %d characters', true), $idLength['min'], $idLength['max']), array('class' => 'attention') ) ) );
↓
<div class="input text"> <label for="UserUsername">UserId</label> <input name="data[User][username]" maxlength="12" value="" id="UserUsername" type="text"> <div class="attention">Between 4 to 12 characters</div> </div>