<?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('admin@jdmnz.com');
$email->setTo('howardgrigg@gmail.com');
$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'));
}
}
?>