Advertisement
Guest User

Untitled

a guest
Feb 6th, 2013
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.  
  5. CREATE TABLE `villains` (
  6. `id` int(11) NOT NULL AUTO_INCREMENT,
  7. `name` varchar(255) NOT NULL,
  8. `mode` varchar(255) NOT NULL,
  9. PRIMARY KEY (`id`)
  10. ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
  11.  
  12. --
  13. -- Dumping data for table `villains`
  14. --
  15.  
  16. INSERT INTO `villains` VALUES(1, 'Joker', 'employer');
  17. INSERT INTO `villains` VALUES(2, 'Kingpin', '');
  18.  
  19. */
  20.  
  21. class FormVillain extends Zend_Form
  22. {
  23. public function init()
  24. {
  25. $id = new Zend_Form_Element_Select("id");
  26. $id->setRegisterInArrayValidator(false)->addValidator(
  27. new Zend_Validate_Db_RecordExists(
  28. array(
  29. 'table' => 'villains',
  30. 'field' => 'id',
  31. 'exclude' => "mode != 'employer'"
  32. )
  33. ));
  34.  
  35. $this->addElement($id);
  36. }
  37. }
  38.  
  39. if (!empty($_POST))
  40. {
  41. $form = new FormVillain();
  42.  
  43. if ($form->isValid($_POST))
  44. {
  45. $values = $form->getValues();
  46. var_dump($values);
  47. }
  48. else
  49. var_dump($form->getMessages());
  50. }
  51.  
  52. ?>
  53.  
  54. <form method='post'>
  55. <select name='id'>
  56. <option value='1'>Joker</option>
  57. <option value='2'>Kingpin</option>
  58. <option value='3'>Poison Ivy</option>
  59. </select>
  60.  
  61. <input type='submit' value='submit'/>
  62. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement