cakePHP 2.2:带有Ajax加载视图和元素的CFSR安全组件

时间:2013-06-19 11:57:30

标签: security jquery cakephp simplemodal cakephp-2.2

我正在尝试使用CakePHP的CSFR保护安全组件与AJAX一起工作 我有ArtistsDates - 控制器(用于保存艺术家/ DJ所有节目的所有日期),其中包含addedit() - 视图。

此视图通过jQuery AJAX加载到jQuery Modalbox中。 (SimpleModal

 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”-Mode调用。如果提供了数据,则元素显示数据并包含隐藏编辑表单。如果在“NEW”-Mode中调用它,则返回一个空的Form。因此,为ArtistDate - 模型中的每个数据行提供此元素(对于添加新数据,再添加+1个数据集)。

(以下是视图的截图:http://i.stack.imgur.com/Ye10v.png

Security - 组件包含在ArtistDatesController中。不幸的是,$this->Form->request->params既不包含[_Token] - addedit中的addedit_daterow_form也不包含<?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(); ?> - 元素 - 我是否必须在jQuery-AJAX-Function中更改某些内容?

- 编辑1:这就是我的表单代码的样子:

{{1}}

提前多多感谢!

1 个答案:

答案 0 :(得分:0)

找出一种工作方式。
使用

 $.ajax({
    type: 'get'
 .
 .
 });

返回包含令牌的表单。