siegmar
(Siegmar)
1
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
pestaa
(Pestaa)
2
Cancelling a form would normally return the user to the previous page.
qiang
(Qiang Xue)
3
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,
if(isset($_POST['ok'])) $model->validate();
About image path, yes, using Yii::app()->theme->baseUrl.'/images/ok.gif' should be fine.
siegmar
(Siegmar)
4
Hi,
- I missed the theme configuration:
'theme'=>'classic'
Now it works !
- 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