CakePHP2アプリを作成しています。私は、ページの上部にフォームエラーを表示するための最善の方法を模索してきました。エラーを取得するのに役立つ他の投稿をいくつか見つけましたが、正しく表示するためにそれらをループするのに苦労しています。
私のフォームはフィールドの多くの行で構成されています-各行は個別のdb行です(経費請求の一部としての個別の経費)。
エラーを渡すためにコントローラーでこれを設定しています:
$this->set('errors', $this->ExpenseClaim->validationErrors);
これは、この一連のエラーを通過しています。
array(
(int) 0 => array(
'date' => array(
(int) 0 => 'The expense date cannot be blank'
),
'sitename' => array(
(int) 0 => 'The expense sitename cannot be blank'
),
'detail' => array(
(int) 0 => 'The expense details cannot be blank'
),
'amount' => array(
(int) 0 => 'The expense amount cannot be blank'
),
'total' => array(
(int) 0 => 'The expense total should not be blank'
)
),
(int) 1 => array(
'date' => array(
(int) 0 => 'The expense date cannot be blank'
),
'sitename' => array(
(int) 0 => 'The expense sitename cannot be blank'
),
'detail' => array(
(int) 0 => 'The expense details cannot be blank'
),
'amount' => array(
(int) 0 => 'The expense amount cannot be blank'
),
'total' => array(
(int) 0 => 'The expense total should not be blank'
)
)
)
エラーを取り除くためにさまざまなforeachループを試しましたが、ネストのレベルが原因で失敗しています。誰かが私を正しい方向に向けることができますか?
「行1の経費日を空白にすることはできません」のようなエラーが必要です。
私はjQueryを使用して行を挿入しているので、フォームヘルパーに頼ることはできません。
前もって感謝します。