Validation data

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

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????

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

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