我有一个带有标题的默认布局(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 执行请求操作,以便使用表单验证并以正确的方式设置表单字段,以便使用 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 被调用的错误。因此,当我在标题中提交表单时,我的其他表单也被提交。
如果我删除元素中的请求操作并将 Form => create 替换为:
echo $this->Form->create('null', array('url' => '/bestelling/modal_ext'));
它工作正常,但随后我失去了此表单中的验证,并且 $request->data 更改,因为该值不是像 [Bestelling] [fieldname] 这样的数组。数组结构的改变不是什么大问题,但我想尝试以正确的方式去做。有人可以帮助我朝着正确的方向解决这个问题。我对 cakephp 很陌生,但我认为调用动作的方式不是由我的程序以正确的方式完成的。