Hi,
I am testing Yii migrating some ASP.NET Forms.
I have created two image buttons at the end of the Insert/Update Form: "Cancel" and "OK".
Both work, but when I click "Cancel" Yii tries to validate the Form.
Is there any way to configure Yii to ignore validation ?
ASP.NEt has the following option:
CausesValidation="false"
Also, how do I create a URL using Yii functions, instead of hard-coding, to reference the image in the component below:
<%= echo CHtml::imageButton('http://localhost/php/exemployii/images/ok.gif',array('name'=>'btnOK')); %>
I have already an 'images' directory under "classes" theme but it did not work:
Yii::app()->theme->baseUrl . '/images/ok.gif'
Thanks
Page 1 of 1
How to avoid validation ?
#2
Posted 09 July 2009 - 06:39 AM
Cancelling a form would normally return the user to the previous page.
#3
Posted 09 July 2009 - 06:58 AM
In Yii, you need to check if it is an OK or Cancel button. Based on this result, you determine whether to do validation. For example,
About image path, yes, using Yii::app()->theme->baseUrl.'/images/ok.gif' should be fine.
if(isset($_POST['ok'])) $model->validate();
About image path, yes, using Yii::app()->theme->baseUrl.'/images/ok.gif' should be fine.
#4
Posted 09 July 2009 - 10:19 AM
Hi,
1. I missed the theme configuration:
'theme'=>'classic'
Now it works !
2. I have not found "validate()" but the following code, with "save()", works fine:
public function actionCreate()
{
$model=new Cidade;
if(isset($_POST['Cidade']))
{
if(isset($_POST['btnOK']))
{
$model->attributes=$_POST['Cidade'];
if($model->save())
$this->redirect(array('admin'));
}
else
$this->redirect(array('admin'));
}
$this->render('create',array('model'=>$model));
}
Thanks
1. I missed the theme configuration:
'theme'=>'classic'
Now it works !
2. I have not found "validate()" but the following code, with "save()", works fine:
public function actionCreate()
{
$model=new Cidade;
if(isset($_POST['Cidade']))
{
if(isset($_POST['btnOK']))
{
$model->attributes=$_POST['Cidade'];
if($model->save())
$this->redirect(array('admin'));
}
else
$this->redirect(array('admin'));
}
$this->render('create',array('model'=>$model));
}
Thanks
Share this topic:
Page 1 of 1

Help













