ヘッダー付きのデフォルト レイアウト (default.ctp) があります。このヘッダーには、次のコードで各ページに表示される検索フォームがあります。
echo $this->Form->create('null', array('url' => '/search/result'),array(
'inputDefaults' => array(
'label' => false,
'div' => false
)
));
echo $this->Form->input('search_query', array('label' => false, 'div' => false, 'type' => 'tel','class' => 'input-small', 'id' => 'appendedInputButton', 'placeholder' => 'Input search'));
echo $this->Form->button('Search', array('class' => 'btn'));
echo $this->Form->end()
この default.ctp ファイルでは、次の行で twitterbootstrap 入力モーダル オーバーレイを呼び出します。この要素はすべてのページで使用されます。
<!-- Add order modal -->
<?php echo $this->element('add_customer_order');?>
この要素では、bestelling/modal_ext に対して request アクションを実行して、フォーム検証が使用され、フォームフィールドが正しい方法でセットアップされ、bestelling コントローラーで保存できるようにします。次のコードは要素にあります。
<?php
$this->requestAction('Bestelling/modal_ext');//Include BestellingController modal_ext
?>
<!-- Add order modal -->
<div id="Bestellingtoevoegen" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Add customer order</h3>
</div>
<div class="modal-body">
<div class="row-fluid">
<div class="span8">
<?php
echo $this->Form->create('Bestelling');
//echo $this->Form->create('null', array('url' => '/bestelling/modal_ext'));
echo $this->Form->input('bestelnummer', array('type' => 'tel','class' => 'input-small'));
echo $this->Form->input('klantnummer', array('type' => 'tel','class' => 'input-small')); ?>
</div>
<div class="span4">
<br/>
<?php echo $this->Form->checkbox('serial'); echo' <span class="label label-info">Serialcode</span> '; ?>
<br/>
<?php echo $this->Form->checkbox('insured'); echo' <span class="label label-info">Insured</span>'; ?>
<br/>
<?php echo $this->Form->checkbox('giftpaper'); echo' <span class="label label-info">Giftpaper</span>'; ?>
</div>
</div>
<div class="row-fluid">
<div class="span5">
<?php
echo $this->Form->input('titel', array('type' => 'tel', 'id' => 'discription', 'onkeyup' => 'lookupproductnamenew(this.value);', 'onblur' => 'fill();', 'after' => '<div class="suggestionsBox" id="suggestions" style="display: none;">
<img src="images/upArrow.png" style="position: relative; top: -20px; left: 30px;" alt="upArrow" />
<div class="suggestionList" id="autoSuggestionsList">
</div>
</div>'));
?>
</div>
<div class="span7">
<?php
echo $this->Form->input('aantal', array(
'options' => array(
'1' => '1',
'2' => '2',
'3' => '3',
'4' => '4',
'5' => '5',
'6' => '6',
'7' => '7',
'8' => '8',
'9' => '9',
'10' => '10',
'11' => '11',
'12' => '12'),
'div' => 'input-prepend',
'label' => ' ',
'between' => '<span class="add-on">X</span>',
'class' => 'span8',
'id' => 'prependedInput',
));
?>
</div>
</div>
<div class="row-fluid">
<div class="span12">
<?php
echo $this->Form->input('opmerking', array('type' => 'textarea', 'class' => 'span10','rows' => '4', 'cols' => '90'));
?>
</div>
</div>
</div>
<?php
echo $this->Form->hidden('levertijd', array('type' => 'tel', 'id' => 'levertijd', 'onblur' => 'fill();'));
echo $this->Form->hidden('prijs', array('type' => 'tel', 'id' => 'prijs', 'onblur' => 'fill();'));
echo $this->Form->hidden('artikelnummer', array('type' => 'tel', 'id' => 'artikelnummer', 'onblur' => 'fill();'));
echo $this->Form->hidden('ean', array('type' => 'tel', 'id' => 'ean', 'onblur' => 'fill();'));
echo $this->Form->hidden('overtime', array('type' => 'tel', 'id' => 'overtime', 'onblur' => 'fill();'));
echo $this->Form->hidden('productgroep', array('type' => 'tel', 'id' => 'productgroep', 'onblur' => 'fill();'));
?>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<?php
echo $this->Form->button('Save', array('class' => 'btn btn-primary'));echo'<br/>';
echo $this->Form->end();
?>
</div>
</div>
<!-- End Add order modal -->
ヘッダーにフォームを送信すると、フォームから /search/result に送信され、データが送信されたことを確認できますが、bestellingcontroller が呼び出されたというエラーも表示されます。したがって、ヘッダーでフォームを送信すると、他のフォームも送信されます。
要素の request アクションを削除し、 Form => create を次のように置き換えると:
echo $this->Form->create('null', array('url' => '/bestelling/modal_ext'));
それは正常に動作しますが、値が [Bestelling][fieldname] のような配列ではないため、このフォームの検証が失われ、$request->data が変更されます。配列の構造の変更は大きな問題ではありませんが、正しい方法で行いたいと考えています。誰かがこの問題を解決するために正しい方向に私を助けることができます. 私は CakePHP に非常に慣れていませんが、アクションを呼び出す方法が私のプログラムによって正しく行われていないと思います。