Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. <?php
  2.  
  3. echo $this->Form->create();
  4. $options = array('1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9', '10' => '10' );
  5. $attributes = array('legend' => false);
  6.  
  7. ?>
  8.  
  9. <div class="answers">
  10. <?php
  11. echo $this->Form->radio('answer1', $options, $attributes);
  12. ?>
  13. </div>
  14.  
  15. public $validate = array(
  16. 'answer1' =>array(
  17. 'rule' => 'notEmpty',
  18. 'message' => 'Please choose an answer'
  19. )
  20. );
  21.  
  22. $fields = array('answer1', 'answer2', 'answer3'); //all fields you need to validate
  23. foreach($fields as $field) {
  24. $validate[$field] = array(
  25. 'rule' => 'notEmpty',
  26. 'message' => 'Please choose an answer'
  27. );
  28. }
  29.  
  30. public $validate = array(
  31. 'function' => array(
  32. 'allowedChoice' => array(
  33. 'rule' => array('inList', array('1', '2', '3', '4')) //And so on
  34. )
  35. )
  36. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement