Guest User

Untitled

a guest
May 26th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. <?php
  2. /**
  3. * Defines the HomePage page type
  4. */
  5.  
  6. class HomePage extends Page {
  7. static $db = array(
  8. );
  9. static $has_one = array(
  10. );
  11.  
  12. static $icon = "tutorial/images/treeicons/home";
  13.  
  14. function LatestNews($num=5) {
  15. $news = DataObject::get_one("ArticleHolder");
  16. return ($news) ? DataObject::get("ArticlePage", "ParentID = $news->ID", "Date DESC", "", $num) : false;
  17. }
  18.  
  19.  
  20. }
  21.  
  22. class HomePage_Controller extends Page_Controller {
  23.  
  24. function BrowserPollForm() {
  25. // Create fields
  26. $fields = new FieldSet(
  27. new TextField('Name'),
  28. new OptionsetField('Browser', 'Your Favourite Browser', array(
  29. 'Firefox' => 'Firefox',
  30. 'Internet Explorer' => 'Internet Explorer',
  31. 'Safari' => 'Safari',
  32. 'Opera' => 'Opera',
  33. 'Lynx' => 'Lynx'
  34. ))
  35. );
  36.  
  37. // Create actions
  38. $actions = new FieldSet(
  39. new FormAction('doBrowserPoll', 'Submit')
  40. );
  41.  
  42. return new Form($this, 'BrowserPollForm', $fields, $actions);
  43.  
  44. // Create validator
  45. $validator = new RequiredFields('Name', 'Browser');
  46.  
  47. return new Form($this, 'BrowserPollForm', $fields, $actions, $validator);
  48.  
  49.  
  50. }
  51.  
  52. function doBrowserPoll($data, $form) {
  53. $submission = new BrowserPollSubmission();
  54. $form->saveInto($submission);
  55. $submission->write();
  56.  
  57. Director::redirectBack();
  58. }
  59.  
  60.  
  61.  
  62. }
  63.  
  64.  
  65.  
  66. ?>
Add Comment
Please, Sign In to add comment