yii post a audio file and show CSRF token
i want to post a form included a name text field and file as a sound file
(MP3 and etc.) but when i want to post it , i see an error about CSRF
token ... and when i remove encrypt in my form , i can save it ... i
exactly don't know , Why?
this is my code?
my MODLE:
<?php
class Radio extends CActiveRecord
{
public $id;
public $file;
public $name;
public $date;
public $addby;
public static function model($className=__CLASS__)
{
return parent::model($className);
}
public function tableName()
{
return '{{radio}}';
}
public function rules()
{
return array(
array('name', 'required' ),
array('name,date,addby,file', 'safe'),
array('file', 'file', 'types'=>'mp3,mp4','allowEmpty'=>true),
);
}
public function attributeLabels()
{
return array(
'name'=>'title',
'file'=>'sound file',
);
} }?>
This is my view :
<?php $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
'id'=>'Form_addvoice',
'htmlOptions' =>
array('class'=>'Margindownfrm','enctype'=>'multipart/form-data'),
'type'=>'horizontal',
'enableClientValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
),
));
echo $form->errorSummary($model);?>
<BR>enter code here
<?php echo $form->textFieldRow($model, 'name'); ?>
<?php echo $form->fileFieldRow($model, 'file'); ?>
<BR>
<div class="footer">
<?php $this->widget('bootstrap.widgets.TbButton',
array('buttonType'=>'submit', 'type'=>'primary', 'label'=>'save')); ?>
</div>
<?php $this->endWidget(); ?>
This is my controller:
public function actionChecklistAdd(){
$editid = (int) Yii::app()->getRequest()->getParam('eid',0);
if($editid == 0){
$checklist= new CheckList();
$params['type'] = 'new';
}else{
$checklist = CheckList::model()->findByPk($editid);
$params['type'] = 'update';
}
if(isset($_POST['CheckList'])){
$checklist->name = $_POST['CheckList']['name'];
$checklist->catid= $_POST['CheckList']['catid'];
if(isset($_POST['checklist'])){
$checklist->params = json_encode($_POST['checklist']);
}
if($checklist->validate() && $checklist->save()){
Yii::app()->user->setFlash('success','successed');
$this->redirect(Yii::app()->createUrl("main/checklistList"));
}else{
Yii::app()->user->setFlash('error',' show some error');
}
}
$params['checklist'] = $checklist;
$this->render('ChecklistAdd',$params);
}
thank you dudes ...
No comments:
Post a Comment