Yii Framework Forum: How to avoid validation ? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How to avoid validation ? Rate Topic: -----

#1 User is offline   siegmar 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 07-June 09

Posted 09 July 2009 - 06:35 AM

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
0

#2 User is offline   pestaa 

  • past Yii dev member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 705
  • Joined: 07-May 09
  • Location:Hungary

Posted 09 July 2009 - 06:39 AM

Cancelling a form would normally return the user to the previous page.
0

#3 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,902
  • Joined: 04-October 08
  • Location:DC, USA

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,

if(isset($_POST['ok'])) $model->validate();


About image path, yes, using Yii::app()->theme->baseUrl.'/images/ok.gif' should be fine.
0

#4 User is offline   siegmar 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 07-June 09

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

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users