1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php

class Page extends SiteTree {

  public static $db = array(
  );

  public static $has_one = array(
  );



}

class Page_Controller extends ContentController {


   public function HomePage() {
    return DataObject::get_one('Homepage');
  }



   function ContactForm() {
      // Create fields
      $fields = new FieldSet(
         new EmailField('Email'),
         new TextareaField('Message')
      );

      // Create actions
      $actions = new FieldSet(
         new FormAction('doContact', 'Submit')
      );
 $validator = new RequiredFields('Email', 'Message');
        return new Form($this, 'ContactForm', $fields, $actions, $validator);
   }


 function doContact($data, $form) {
     $data['PageName'] = $this->Title;

    $email = new Email();
      $email->setTemplate('ContactPage_Email');
      $email->setSubject('JDMNZ.com Contact Form');
      $email->setFrom('[email protected]');
      $email->setTo('[email protected]');
      $email->populateTemplate($data);
      $email->send();

      $form->sessionMessage('Thanks for contacting us. We will endeavour to get in touch with you as soon as possible!', 'good'); 

      Director::redirectBack();
   }



  public function init() {
    parent::init();

    // Note: you should use <% require %> tags inside your templates instead of putting Requirements calls here.  However
    // these are included so that our older themes still work
    Requirements::themedCSS("layout");

  }
   
  function RandomProduct() {
  $objects = DataObject::get("ProductPage", "","RAND()", "", 1);
  if(is_object($objects) && $objects->Count()) {
  foreach($objects as $obj) {} // dont need to do anything else!
  }
  return($obj);
  }


    function SearchForm() {
      $searchText = isset($this->Query) ? $this->Query : 'Search';

      $fields = new FieldSet(
         new TextField("Search", "", $searchText)
      );

      $actions = new FieldSet(
         new FormAction('results', 'Go')
      );

      return new SearchForm($this, "SearchForm", $fields, $actions);
   }

   function results($data, $form){
      $data = array(
         'Results' => $form->getResults(),
         'Query' => $form->getSearchQuery(),
         'Title' => 'Search Results'
      );

      return $this->customise($data)->renderWith(array('Page_results','Page'));
   }

}



?>