サブフォームを使用して Zend Framework 1.9 でフォームを作成し、それらのフォームで Zend_JQuery を有効にしています。フォーム自体は問題なく、すべてのエラー チェックなどは正常に機能しています。しかし、私が抱えている問題は、コントローラーで値を取得しようとしているときに、最後のサブフォームのフォームエントリだけを受け取っていることです。
私のマスターフォームクラス(スピードのために省略):
Master_Form extends Zend_Form
{
public function init()
{
ZendX_JQuery::enableForm($this);
$this->setAction('actioninhere')
...
->setAttrib('id', 'mainForm')
$sub_one = new Form_One();
$sub_one->setDecorators(... in here I add the jQuery as per the docs);
$this->addSubForm($sub_one, 'form-one');
$sub_two = new Form_Two();
$sub_two->setDecorators(... in here I add the jQuery as per the docs);
$this->addSubForm($sub_two, 'form-two');
}
}
すべてが表示どおりに機能するように、必要な値を入力せずに送信すると、正しいエラーが返されます。ただし、コントローラーには次のものがあります。
class My_Controller extends Zend_Controller_Action
{
public function createAction()
{
$request = $this->getRequest();
$form = new Master_Form();
if ($request->isPost()) {
if ($form->isValid($request->getPost()) {
// This is where I am having the problems
print_r($form->getValues());
}
}
}
}
これを送信して isValid() を過ぎると、$form->getValues() はフォーム全体ではなく、2 番目のサブフォームの要素のみを返します。