我正在尝试让 CakePHP 的用于 CSFR 保护的安全组件与 AJAX 一起使用。
我有我的ArtistsDates
-Controller(用于保存艺术家/DJ 的所有演出日期),其中包含一个addedit()
- 视图。
此视图通过 jQuery AJAX 加载到 jQuery Modalbox 中。(简单模态)
function artist_dates(request){
.
.
if(request == 'load'){
$.ajax({
type: 'post',
url: $('base').attr('href') + '/artist_dates/addedit/'+artist_id,
success: function(html){
$('#dialog').html(html);
$('#dialog').modal({
modal: false,
maxHeight:'500px',
minHeight:500,
minWidth:750,
});
}
});
}
.
.
}
在此视图中,我的表单呈现为addedit_daterow_form
- 元素。这个元素要么用数据调用,要么以“新”模式调用。如果提供了数据,该元素将显示数据并包含一个隐藏编辑表单。如果在“NEW”模式下调用它,它会返回一个空表单。因此,该元素为ArtistDate
模型中的每个数据行呈现(+1 用于添加新的!)
(这里是视图的截图:http: //i.stack.imgur.com/Ye10v.png)
Security
-组件包含在ArtistDatesController
. 不幸的是,$this->Form->request->params
既不包含[_Token]
在addedit
- 视图中也不在addedit_daterow_form
- 元素中 - 我是否必须更改我的 jQuery-AJAX-Function 中的某些内容?
-- 编辑 1:这就是我的表单代码的样子:
<?php echo $this->Form->create('ArtistDate', array('controller' => 'artist_dates','action' => 'addedit', 'id' => 'artistDateForm_'.$date_nr)); ?>
<?php echo pr($this->Form->request->params); ?>
<?php echo $this->Form->input('ArtistDate.'.$date_nr.'.id',array('type' => 'hidden', 'value' => $date['ArtistDate']['id'])); ?>
<?php echo $this->Form->input('ArtistDate.'.$date_nr.'.artist_id',array('type' => 'hidden', 'value' => $date['ArtistDate']['artist_id'])); ?>
<div class="date">
<?php echo $this->Form->input('ArtistDate.'.$date_nr.'.date', array('type' => 'text','label' => 'Date <span style="font-weight:normal; float:right;">[DD.MM.YYYY]</span>','value' => (!empty($date['ArtistDate']['date']) ? date('d.m.Y',strtotime($date['ArtistDate']['date'])) : ''))); ?>
<?php echo $this->Form->input('ArtistDate.'.$date_nr.'.date_end', array('type' => 'text','label' => 'Enddate <span style="font-weight:normal; float:right;">[DD.MM.YYYY]</span>','value' =>(!empty($date['ArtistDate']['date_end']) ? date('d.m.Y',strtotime($date['ArtistDate']['date_end'])) : ''))); ?>
</div>
<div class="venue">
<?php echo $this->Form->input('ArtistDate.'.$date_nr.'.venue', array('type' => 'text','value' => $date['ArtistDate']['venue'])); ?>
<?php echo $this->Form->input('ArtistDate.'.$date_nr.'.city', array('type' => 'text','value' => $date['ArtistDate']['city'])); ?>
</div>
<div class="link">
<?php echo $this->Form->input('ArtistDate.'.$date_nr.'.venuelink', array('type' => 'text','label' => 'Link <span style="font-weight:normal; float:right;">Venue</span>','value' => $date['ArtistDate']['venuelink'])); ?>
<?php echo $this->Form->input('ArtistDate.'.$date_nr.'.ticketslink', array('type' => 'text','label' => 'Link <span style="font-weight:normal; float:right;">Tickets</span>','value' => $date['ArtistDate']['ticketslink'])); ?>
</div>
<div class="actions">
<?php echo $this->Html->link('','',array('class' => 'buttonsave','onclick' => "artistdate_handling('".$date_nr."','save'); return false;", 'style' => $display_exists, 'escape' => false, 'title' => 'Save')); ?>
<?php echo $this->Html->link('','',array('class' => $approveclass, 'onclick' => "artistdate_handling('".$date_nr."','confirm'); return false;", 'style' => $display_exists, 'escape' => false, 'title' => 'Confirm Show')); ?>
<?php echo $this->Html->link('','',array('class' => 'buttondelete','onclick' => "artistdate_handling('".$date_nr."','delete'); return false;", 'style' => $display_exists, 'escape' => false, 'title' => 'Delete Show')); ?>
<?php echo $this->Html->link('','',array('class' => 'buttonadd','onclick' => "artistdate_handling('".$date_nr."','add'); return false;", 'style' => $display_new, 'escape' => false, 'title' => 'Add Show')); ?>
</div>
<div style="clear:both"></div>
<?php echo $this->Form->end(); ?>
提前非常感谢!