<?php

class MyForm extends Form {

function __construct($controller, $name) {

$fields = new FieldSet(
new TextField('Name', 'Your name'),
new EmailField('Email', 'Email address')
);

$actions = new FieldSet(
new FormAction('doForm', 'Submit')
);

$validator = new RequiredFields(array(
'Name',
'Email'
));

parent::__construct($controller, $name, $fields, $actions, $validator);
}

function forTemplate() {
return $this->renderWith(array(
$this->class,
'Form'
));
}

function doForm($data, $form) {
$email = new ContactPage_Email(
$data['Email'],
'admin@somewhere.com',
'The contact page has been submitted'
);
$email->populateTemplate(array(
'FormData' => new ArrayData($data)
));
$email->send();

Director::redirect('finished-page'); // Redirect to the page with the URLSegment 'finished-page'
}

}

?>