在我的索引页上,我的表的每一行都有复选框。
要编辑选定的项,我使用javascript/jquery获取复选框的类,构建in数组,然后将其发布到控制器中的edit selected方法。
现在,这一切都可以完美地工作,但当我的App Controller中启用了Security时,我的帖子就会变得黑洞,数组也不会张贴。
这是我的index.ctp文件:
<table id="indexTable">
<thead><tr>
<th> <?php echo $this->Form->checkbox('select_all', array('value' => 'select_all')); ?> </th>
<th> <?php echo $this->Paginator->sort('id', 'ID'); ?> </th>
<th> <?php echo $this->Paginator->sort('name', 'Name'); ?> </th>
<th>Auto Offset </th> <th>UTC Offset Sec </th> <th>In Month </th>
<th>In Week </th> <th>In Dow </th> <th>In Hour </th> <th>Out Month </th>
<th>Out Week </th> <th>Out Dow </th> <th>Out Hour </th> <th>Offset Sec </th>
<th>DST Ref </th> <th>Actions </th>
</tr></thead>
<tbody>
<?php
$this->Form->create('LocalClock');
foreach($localClocks as $LocalClock) { ?>
<tr>
<td> <?php echo $this->Form->checkbox('LocalClocks'.$LocalClock['LocalClock']['id'], array('value' => $LocalClock['LocalClock']['id'], 'hiddenField' => false));?> </td>
<td> <?php echo $LocalClock['LocalClock']['id']; ?> </td>
<td> <?php echo $LocalClock['LocalClock']['name']; ?> </td>
<td> <?php echo $LocalClock['LocalClock']['auto_offset']; ?> </td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<!-- This <div> contains all the actions that can be performed on the Local Clocks. -->
<div>
<p>
<span style="float: left">
<?php echo $this->Html->link(__('Edit All Items'), array('action' => 'editAll'), array('class' => 'link'));?>
</span>
<span style="float: left">
<?php echo $this->Html->link(__('Edit Selected Items'), array('action' => 'lceditSelected'), array('class' => 'general_dialog'));?>
</span>
<span style="float: right">
<?php echo $this->Html->link(__('Delete Selected Items'), array('action' => 'deleteSelected'), array('class' => 'general_dialog'));?>
</span>
<?php $this->Form->end(); ?>
</p>
</div>我拿出了一些不重要的东西。问题出在我的编辑选定和删除选定的功能上。
下面是javascript代码,它等待用户单击,然后构建数组以发布到控制器操作:
$('.general_dialog').live('click', function()
{
$.ajaxSetup({ async: false });
var $selDialog = $("#general_dialog").dialog(
{
autoOpen: false,
modal: true,
});
var postInfo = $('#LocalClockIndexForm').serialize();
$.ajax({
url: $(this).attr('href'),
type: "post",
data: postInfo,
success: function (response)
{
alert('success');
},
error: function()
{
alert("failed");
}
});
$selDialog.load($(this).attr('href'), function ()
{
$selDialog.dialog('open');
});
return false; // Ensure the controller does not redirect to the actual edit page
});任何关于如何让它在不被黑洞的情况下工作的帮助都将不胜感激。
提前感谢
我将$this->Form->create('LocalClock')和$this->Form->end()添加到表中,并将$.post()和$.ajax()调用切换为。
如果我发送序列化的表单,我不会得到一个黑洞,但当我查看发布的数据时,它不包括任何复选框ids。
发布于 2012-07-28 18:04:23
您的示例缺少表单标记。
您需要使用表单帮助器创建和结束表单,以确保安全令牌包含在表单生成中:
$this->Form->create();
// Other form elements here.
$this->Form->end();发布于 2012-10-10 17:27:35
您是否尝试过修改crsf防护策略?如果您使用相同的令牌重新加载页面,则Security组件将对请求设置黑洞。
var $components = array('Security'=>array('csrfUseOnce'=>false));https://stackoverflow.com/questions/11694865
复制相似问题