I'm trying to create an ereg on a select option in object orientated programming for validation. Though it is always returning true even though the selected option isn't part of the ereg!
In my class I have the following:
function makeSelect($category, $fieldName){
$a = '<div>'."\n";
$a .= "<select name='$fieldName'>"."\n";
$a .= "<option value='' selected='true' disabled='disabled'>Pick Category</option>\n";
foreach ($category as $value){
$a .= "<option value='$value'>$value</option>"."\n";
}
$a .= "</select>"."\n";
$a .= "</div>"."\n";
return $a;
}
function checkSelect($selectName){
if(ereg('^[Pick]', $selectName)){
$this->messageArray[$selectName] = "<span class='fail'>Please select field</span>";
$this->testArray[$selectName] = false;
}
else {
$this->messageArray[$selectName] = "<span class='ok'>Sweet</span>";
$this->testArray[$selectName] = true;
}
}
In my main file I'm setting the array as
$category = array(
1=>'First Category',
2=>'Second Category',
3=>'Third Category',
4=>'Fourth Category'
);
And calling the checkSelect function as
$oForm->checkSelect('category');