Validation Time

Hey guys, i’m currently working on my new project…

This is my admin view :

This is my input view :

Now i want to validate the time fields, based on this :

  1. If the ‘NIP Dosen Mata Kuliah’ already existed with the same ‘Jam Masuk’ & ‘Jam Keluar’ then it’s invalid

  2. If the ‘NIP Dosen Mata Kuliah’ already existed but with different ‘Jam Masuk’ & ‘Jam Keluar’ then it’s valid to save

  3. If the ‘Kode Ruang’ already existed with the same ‘Nip Dosen Mata Kuliah’ and the same ‘Jam Masuk’ & ‘Jam Keluar’, then it’s invalid

  4. If the ‘Kode Ruang’ already existed but with different ‘Nip Dosen Mata Kuliah’ and ‘Jam Masuk’ & ‘Jam Keluar’, then it’s valid to save

Anyone can help me…

First step. You can make your own validation rules in your model.




	public function rules()

	{

		array('timefield', 'validateTimeField'),

	}






	// Custom validation for time field.

	public function validateTimeField($attribute,$params)

	{

		if(do some checks here...)

		{

			$this->addError($attribute, $this->getAttributeLabel('Error because bla bla.');	

		}

		if(do some more checks here...)

		{

			$this->addError($attribute, $this->getAttributeLabel('Error because...');	

		}

	}	



Thankyou, i will try this. :)

Great, don’t hesitate if you got more questions or if you want to show us what the result is you’ve made.