Yii Framework Forum: Validation data - Yii Framework Forum

Jump to content

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

Validation data Rate Topic: -----

#1 User is offline   kitty10 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 139
  • Joined: 13-April 10

Posted 20 April 2010 - 08:55 AM

I have a problem with validation of data.Don't consider the fields 'required'. Even if I leave them empty,the framework saves anyway form.Anybody can help me?
0

#2 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,651
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 20 April 2010 - 09:08 AM

View Postkitty10, on 20 April 2010 - 08:55 AM, said:

I have a problem with validation of data.Don't consider the fields 'required'. Even if I leave them empty,the framework saves anyway form.Anybody can help me?


Which framework version? Scenario (e.g create or update)? Inherited rules? Calling save(false) i.e no validation? Please show us your rules() function.

/Tommy
Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
0

#3 User is offline   kitty10 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 139
  • Joined: 13-April 10

Posted 20 April 2010 - 09:19 AM

View Posttri, on 20 April 2010 - 09:08 AM, said:

Which framework version? Scenario (e.g create or update)? Inherited rules? Calling save(false) i.e no validation? Please show us your rules() function.

/Tommy

public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('DIPART_DIPART_ID, FACOLTA_FACOLTA_ID, ANAGRA_ANAGRA_ID', 'required'),
array('DIPART_DIPART_ID, FACOLTA_FACOLTA_ID, PUNTEGGIO_VPS, S_S_D_S_S_D_ID, ANAGRA_ANAGRA_ID', 'numerical', 'integerOnly'=>true),
array('FINANZ_CC_EURO, FINANZ_CAP_EURO', 'numerical'),
array('FASCIA_DOCENTE, LABORATORIO, RUOLO', 'length', 'max'=>50),
array('NOTE, ASSOCIAZIONI, HONORS, MEMBERSHIP, EDUCATION, TITOLI, RICONOSCIMENTI, CONFERENCE, CONVEGNI, RICEVIMENTO', 'length', 'max'=>200),
array('RICHIESTO_FINANZ, SUCCESSO_FINANZ, INDENNITA_SANITARIA', 'length', 'max'=>2),
array('INTERESSI_GENERALI, SCIENTIFIC_INTERESTS, RICERCA, RESEARCH', 'length', 'max'=>800),
array('BACKGROUND, CARRIERA', 'length', 'max'=>400),
array('URL', 'length', 'max'=>100),
array('DATA_ASSUNZIONE, DATA_NOMINA, DATA_CONFERMA, ANNO_VPS, DATA_FINE', 'safe'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('MATRICOLA, DIPART_DIPART_ID, FACOLTA_FACOLTA_ID, DATA_ASSUNZIONE, FASCIA_DOCENTE, DATA_NOMINA, DATA_CONFERMA, LABORATORIO, PUNTEGGIO_VPS, ANNO_VPS, NOTE, S_S_D_S_S_D_ID, RICHIESTO_FINANZ, SUCCESSO_FINANZ, FINANZ_CC_EURO, FINANZ_CAP_EURO, INTERESSI_GENERALI, ASSOCIAZIONI, SCIENTIFIC_INTERESTS, HONORS, MEMBERSHIP, EDUCATION, TITOLI, RICERCA, BACKGROUND, RICONOSCIMENTI, CARRIERA, RESEARCH, URL, CONFERENCE, CONVEGNI, DATA_FINE, ANAGRA_ANAGRA_ID, RICEVIMENTO, INDENNITA_SANITARIA, RUOLO', 'safe', 'on'=>'search'),
);
}

This is an example...
I have the version 1.1.1, all scenario create,update...
where i can check the validation or save if is true or false????
0

#4 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,651
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 20 April 2010 - 10:53 AM

View Postkitty10, on 20 April 2010 - 09:19 AM, said:

public function rules()
{
return array(
array('DIPART_DIPART_ID, FACOLTA_FACOLTA_ID, ANAGRA_ANAGRA_ID', 'required'),
array('DIPART_DIPART_ID, FACOLTA_FACOLTA_ID, PUNTEGGIO_VPS, S_S_D_S_S_D_ID, ANAGRA_ANAGRA_ID', 'numerical', 'integerOnly'=>true),
...
);
...
}


I suggest you try setting the allowEmpty option to false
    array('DIPART_DIPART_ID, ...', 'numerical', 'integerOnly'=>true, 'allowEmpty'=>false),


If still no luck, try commenting out every rule but 'required'.

The parameter to save() (probably in your controller code) defaults to true, meaning validation will take place.

(not tested)
/Tommy

This post has been edited by tri: 20 April 2010 - 11:29 AM

Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
0

#5 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,651
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 22 April 2010 - 08:56 PM

View Posttri, on 20 April 2010 - 10:53 AM, said:

I suggest you try setting the allowEmpty option to false
    array('DIPART_DIPART_ID, ...', 'numerical', 'integerOnly'=>true, 'allowEmpty'=>false),



My suggestion turned out to be incorrect.

I had a similar case today. I have a hidden field intended to be populated by jQuery code. The attribute in a fresh model instance obviously is created with integer type (according to db schema). The integer zero value will always pass the 'required' validation. The problem seems to be solved by explicitly initializing the attribute to string type (in the model). Thus it will be forced to validate as an empty numeric string, if left untouched.

In your case (if applicable) that would be:
  public $DIPART_DIPART_ID = '';
  public $... = '';

/Tommy
Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
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