Advertisement
Guest User

Untitled

a guest
Mar 7th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.60 KB | None | 0 0
  1. static $allowed_actions = array(
  2.         'ApplicationForm'
  3.     );
  4.  
  5.     function ApplicationForm() {
  6.         $fields = new FieldSet(
  7.             new TextField('FirstName', 'First Name*'),
  8.             new TextField('LastName', 'Last Name*'),
  9.             new EmailField('Email', 'Email*'),
  10.             new TextField('PhoneNumber','Phone Number'),
  11.             new DropdownField('Location','Select Location*', array('Bunrley, UK'=> 'Bunrley, UK', 'Derby, UK' => 'Derby, UK', 'East Granby, CT, US' => 'East Granby, CT, US')),
  12.             new DropdownField('Role','Select Role*', array('CNC Machining'=> 'CNC Machining', 'Conventional Machining' => 'Conventional Machining', 'Welding' => 'Welding'))
  13.         );
  14.  
  15.         // Create action
  16.         $actions = new FieldSet(
  17.             new FormAction('SendContactForm', 'Send')
  18.         );
  19.  
  20.         // Create Validators
  21.         $validator = new RequiredFields('FirstName', 'LastName', 'Email', 'Location', 'Role');
  22.         return new Form($this, 'ApplicationForm', $fields, $actions, $validator);
  23.     }
  24.  
  25.     function SendContactForm($data, $form) {
  26.         $From = $data['Email'];
  27.         if ($this->Location == "Bunrley, UK") {
  28.             $To = 'example@email.co.uk';
  29.         }
  30.         $Subject = "Website Contact message";
  31.         $email = new Email($From, $To, $Subject);
  32.         $email->setTemplate('ContactEmail');
  33.         $email->populateTemplate($data);
  34.         $email->send();
  35.         Director::redirect($this->Link("?success=1"));
  36.     }
  37.  
  38.      public function Success() {
  39.         return isset($_REQUEST['success']) && $_REQUEST['success'] == "1";
  40.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement