Guest User

Untitled

a guest
Jul 18th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. <?php
  2. Class FriendGetFriendPage extends Page{
  3. static $db = array( //data saved within this page
  4. 'Subject'=>'Varchar(100)',
  5. 'Message'=>'Text',
  6. 'RegPage'=>'Text',
  7. 'SuccessTitle'=>'Text',
  8. 'SuccessMessage'=>'Text'
  9.  
  10. );
  11.  
  12. function getCMSFields(){
  13. //Fields created for sending out registration confirmations
  14. $fields=parent::getCmsFields();
  15. $fields->addFieldToTab("Root.Settings", new TextField('Subject', "Email Subject Line"));
  16. $fields->addFieldToTab("Root.Settings", new TextField('RegPage', "Registration Page Link"));
  17. $fields->addFieldToTab("Root.Settings", new TextareaField('Message', "Email Message"));
  18. $fields->addFieldToTab("Root.SubmitPage", new TextField('SuccessTitle', "Heading"));
  19. $fields->addFieldToTab("Root.SubmitPage", new TextareaField('SuccessMessage', "Message"));
  20. return $fields;
  21. }
  22.  
  23. }
  24. Class FriendGetFriendPage_Controller extends Page_Controller{
  25. function FriendForm(){
  26. //create fields
  27. $fields = new FieldSet(
  28. //Message to be sent to friend
  29. new TextareaField('FriendMessage', 'Your Message:','5','40'),
  30. new TextField('FriendName', 'Your Name'),
  31. new EmailField('EmailFrom', 'Your Email'),
  32. //Friend1 Email1
  33. new TextField('F1', 'Friend 1: First Name'),
  34. new EmailField('E1', 'Email Address'),
  35. //Friend2 Email2
  36. new TextField('F2', 'Friend 2: First Name'),
  37. new EmailField('E2', 'Email Address'),
  38.  
  39. //$EmailFrom=str_replace("%40","@",$EmailFrom);
  40. new TextField('F3', 'Friend 3: First Name'),
  41. new EmailField('E3', 'Email Address'));
  42. //submit
  43. $actions= new FieldSet(
  44. new ImageFormAction('SubmitFriendForm', 'Submit', '/themes/richmond/images/button.png', '/themes/richmond/images/button_over.png')
  45. );
  46. //Required Fields
  47. $Validator = new RequiredFields('FriendMessage', 'F1','F2'.'F3','E1','E2','E3','EmailFrom','FriendName');
  48.  
  49. return new Form($this, 'FriendForm',$fields, $actions, $Validator);
  50. }
  51.  
  52. function SubmitFriendForm($data, $form)
  53. {
  54. $i=1;
  55. //for loop to iterate through fields
  56. for ($counter =0; $counter < 3; $counter++)
  57. {
  58. //save fields to database if they are not empty
  59. $submission = new FriendGetFriend();
  60. $submission->FriendName=$data['FriendName'];
  61. $submission->FriendEmail=$data['EmailFrom'];
  62. $submission->GetFriendName=$data['F'.$i];
  63. $submission->GetFriendEmail=$data['E'.$i];
  64. $submission->write();
  65.  
  66. //send email
  67. //$GetFriendName =$data['F'.$counter]; //change variable for sending in email
  68. $GetFriendEmail=$data['E'.$i];
  69. $From=$data['EmailFrom'];
  70. $To=$GetFriendEmail;
  71. $Subject=$this->Subject;
  72. $email= new Email($From, $To, $Subject);
  73. $email->setTemplate('FriendGetFriendEmail');
  74. //populate the email template and add message to the
  75. $EmailData = &$data; //copies data array into a new array
  76. $EmailData['name']=$data['FriendName'];
  77. $EmailData['GetFriendName']=$data['F'.$i];
  78. $EmailData['Message']=$this->Message;
  79. $EmailData['RegPage']=$this->RegPage;
  80. $EmailData['FMessage']=$data['FriendMessage'];
  81. $EmailData['counter']=$data['F'.$i];
  82. $email->populateTemplate($EmailData); //pass this array into the emailTemplate
  83. $email->send();
  84. //increment i
  85. $i++;
  86. //Redirects the success url
  87. Director::redirect(Director::baseURL(). $this->URLSegment."/?Success=1");
  88.  
  89.  
  90. }
  91. }
  92.  
  93. public function Success(){
  94. //returns the user to the success url once the form has been submitted
  95. return isset($_REQUEST['Success']) && $_REQUEST['Success']== "1";
  96. }
  97.  
  98. }
Add Comment
Please, Sign In to add comment