Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static $allowed_actions = array(
- 'ApplicationForm'
- );
- function ApplicationForm() {
- $fields = new FieldSet(
- new TextField('FirstName', 'First Name*'),
- new TextField('LastName', 'Last Name*'),
- new EmailField('Email', 'Email*'),
- new TextField('PhoneNumber','Phone Number'),
- new DropdownField('Location','Select Location*', array('Bunrley, UK'=> 'Bunrley, UK', 'Derby, UK' => 'Derby, UK', 'East Granby, CT, US' => 'East Granby, CT, US')),
- new DropdownField('Role','Select Role*', array('CNC Machining'=> 'CNC Machining', 'Conventional Machining' => 'Conventional Machining', 'Welding' => 'Welding'))
- );
- // Create action
- $actions = new FieldSet(
- new FormAction('SendContactForm', 'Send')
- );
- // Create Validators
- $validator = new RequiredFields('FirstName', 'LastName', 'Email', 'Location', 'Role');
- return new Form($this, 'ApplicationForm', $fields, $actions, $validator);
- }
- function SendContactForm($data, $form) {
- $From = $data['Email'];
- if ($this->Location == "Bunrley, UK") {
- $To = 'example@email.co.uk';
- }
- $Subject = "Website Contact message";
- $email = new Email($From, $To, $Subject);
- $email->setTemplate('ContactEmail');
- $email->populateTemplate($data);
- $email->send();
- Director::redirect($this->Link("?success=1"));
- }
- public function Success() {
- return isset($_REQUEST['success']) && $_REQUEST['success'] == "1";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement