Guest User

Untitled

a guest
Jul 18th, 2018
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. <?php
  2. class HomePage extends Page{
  3. static $db = array(
  4. 'Subject'=>'Varchar(100)',
  5. 'Message'=>'Text',
  6. 'SuccessTitle'=>'Text',
  7. 'SuccessMessage'=>'Text'
  8. //Fields created for sending out registration confirmations
  9.  
  10. );
  11.  
  12. static $has_one =array(
  13. 'RightImage' => 'Image'
  14. );
  15.  
  16. function getCMSFields(){
  17. $fields = parent::getCMSFields();
  18. $fields->addFieldToTab("Root.Settings", new TextField('Subject', "Email Subject Line"));
  19. $fields->addFieldToTab("Root.Settings", new TextareaField('Message', "Email Message"));
  20. $fields->addFieldToTab("Root.Images", new ImageField('RightImage', "Image on right of home page"));
  21. $fields->addFieldToTab("Root.OnSubmission", new TextField('MailFrom', "Email sent from"));
  22. $fields->addFieldToTab("Root.OnSubmission", new TextField('RegSubject', "Email Subject"));
  23. $fields->addFieldToTab("Root.OnSubmission", new TextareaField('RegMessage', "Email Message"));
  24. $fields->addFieldToTab("Root.SubmitPage", new TextField('SuccessTitle', "Heading"));
  25. $fields->addFieldToTab("Root.SubmitPage", new TextareaField('SuccessMessage', "Message"));
  26. return $fields;
  27. }
  28. }
  29.  
  30. class HomePage_Controller extends Page_Controller {
  31. function TeacherForm(){
  32. //feilds for TeacherForm
  33. $fields = new FieldSet(
  34. new TextField('Name'),
  35. new TextField('Surname'),
  36. new EmailField('Email'),
  37. new TextField('Position'),
  38. new TextField('City'),
  39. new TextField('School'));
  40. //action submission
  41. $action= new FieldSet(
  42. new ImageFormAction('doTeacherForm', 'Submit', '/themes/richmond/images/button.png', '/themes/richmond/images/button_over.png')
  43. );
  44. //Validate
  45. $Validator = new RequiredFields ('Name','Surname','Email','City','Position','School');
  46.  
  47. return new Form($this,'TeacherForm', $fields,$action, $Validator);
  48. }
  49. function doTeacherForm($data, $form){
  50. $submission = new TeacherFormSubmission();
  51. $form->saveInto($submission);
  52. $submission->write();
  53.  
  54. $From=$this->MailFrom;
  55. //$To='josh@subvert.co.nz';
  56. //$To=$data['Email'];
  57. $To='monica@localhost';
  58. $Subject=$this->RegSubject;
  59. $email= new Email($From, $To, $Subject);
  60. $email->setTemplate('TeacherSubmissionEmail');
  61. //populate the email template and add message to the
  62. $EmailData = &$data; //copies data array into a new array
  63. $HtmlEmail=str_replace("@", "%40", $To); //replace @ sign for use in the url
  64. $EmailData["Message"]=$this->RegMessage; //add the email message to the array
  65. $EmailData["HtmlEmail"]=$HtmlEmail;
  66. $email->populateTemplate($EmailData); //pass this array into the emailTemplate
  67. $email->send();
  68. //Redirects the success url
  69. Director::redirect(Director::baseURL(). $this->URLSegment . "/?Success=1");
  70. }
  71. public function Success()
  72. {
  73. //returns the user to the success url once the form has been submitted
  74. return isset($_REQUEST['Success']) && $_REQUEST['Success']== "1";
  75. }
  76.  
  77. }
Add Comment
Please, Sign In to add comment