Daniel
Daniel

Reputation: 667

Zend Framework Filter Input ENUM

I'm using Zend Framework 1.12.3 for a project I'm developing.

I use Filter Input and need to make sure the value is within certain values (ENUM). (e.g. frequency must be either 'instantly', 'daily' or 'weekly').

How can I accomplish this?

Thanks

Upvotes: 2

Views: 876

Answers (2)

Mubo
Mubo

Reputation: 1070

If i understood you correctly you may be looking some thing like this:- You can use input form validators , if the value is to be among certain value.

// create text input for age // should contain only integer values between 1 and 100

$age = new Zend_Form_Element_Text('age');
$age  ->setLabel('Age:')
      ->setOptions(array('size' => '4'))
      ->setRequired(true)
      ->addValidator('Int')  //must be an Integer
      ->addValidator('Between', false, array(1,100)); //from 1 to 100

The same but just using Zend_Validate class.

// create text input for age
// should contain only integer values between 1 and 100


 $age = new Zend_Form_Element_Text('age');
 $age->setLabel('Age:')
    ->setOptions(array('size' => '4'))
    ->setRequired(true)
    ->addValidator(new Zend_Validate_Int())
    ->addValidator(new Zend_Validate_Between(1,100));

Upvotes: 0

doydoy44
doydoy44

Reputation: 5772

Personally, I would use a validator to do this

  $validator = new Zend_Validate_InArray(array('ENUM1' => 'value 1',
                                               'ENUM2' => 'value 1',
                                               'ENUM3' => 'value 3'));
   $element->addValidator($validator);

Upvotes: 5

Related Questions