I have a drop down list where users can select their timezone on a form. On submit, I'm looking for the best way to validate the timezone input field using Yii rules.
I'm able to get an array of timezones in PHP using the following:
DateTimeZone::listIdentifiers(DateTimeZone::ALL)
The values are like this (an indexed key with a timezone value):
Array([0]=>'Pacific/Midway',[1]=>'Pacific/Niue',...);
My select box looks like this:
<select name="timezone" id="timezone">
<option value="Pacific/Midway">Pacific/Midway (GMT-11:00)</option>
<option value="Pacific/Niue">Pacific/Niue (GMT-11:00)</option>
...
</select>
I tried the following:
public function rules() {
return array(
array('timezone','in','range'=>DateTimeZone::listIdentifiers(DateTimeZone::ALL)),
array(timezone','required'),
);
} // rules()
But it never validates, I think because the the range is a multidimensional array and in order for range to work it needs to be just an array of values like array('value1','value2'); Is that true?
Is there a better approach?