Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- Class FriendGetFriendPage extends Page{
- static $db = array( //data saved within this page
- 'Subject'=>'Varchar(100)',
- 'Message'=>'Text',
- 'RegPage'=>'Text',
- 'SuccessTitle'=>'Text',
- 'SuccessMessage'=>'Text'
- );
- function getCMSFields(){
- //Fields created for sending out registration confirmations
- $fields=parent::getCmsFields();
- $fields->addFieldToTab("Root.Settings", new TextField('Subject', "Email Subject Line"));
- $fields->addFieldToTab("Root.Settings", new TextField('RegPage', "Registration Page Link"));
- $fields->addFieldToTab("Root.Settings", new TextareaField('Message', "Email Message"));
- $fields->addFieldToTab("Root.SubmitPage", new TextField('SuccessTitle', "Heading"));
- $fields->addFieldToTab("Root.SubmitPage", new TextareaField('SuccessMessage', "Message"));
- return $fields;
- }
- }
- Class FriendGetFriendPage_Controller extends Page_Controller{
- function FriendForm(){
- //create fields
- $fields = new FieldSet(
- //Message to be sent to friend
- new TextareaField('FriendMessage', 'Your Message:','5','40'),
- new TextField('FriendName', 'Your Name'),
- new EmailField('EmailFrom', 'Your Email'),
- //Friend1 Email1
- new TextField('F1', 'Friend 1: First Name'),
- new EmailField('E1', 'Email Address'),
- //Friend2 Email2
- new TextField('F2', 'Friend 2: First Name'),
- new EmailField('E2', 'Email Address'),
- //$EmailFrom=str_replace("%40","@",$EmailFrom);
- new TextField('F3', 'Friend 3: First Name'),
- new EmailField('E3', 'Email Address'));
- //submit
- $actions= new FieldSet(
- new ImageFormAction('SubmitFriendForm', 'Submit', '/themes/richmond/images/button.png', '/themes/richmond/images/button_over.png')
- );
- //Required Fields
- $Validator = new RequiredFields('FriendMessage', 'F1','F2'.'F3','E1','E2','E3','EmailFrom','FriendName');
- return new Form($this, 'FriendForm',$fields, $actions, $Validator);
- }
- function SubmitFriendForm($data, $form)
- {
- $i=1;
- //for loop to iterate through fields
- for ($counter =0; $counter < 3; $counter++)
- {
- //save fields to database if they are not empty
- $submission = new FriendGetFriend();
- $submission->FriendName=$data['FriendName'];
- $submission->FriendEmail=$data['EmailFrom'];
- $submission->GetFriendName=$data['F'.$i];
- $submission->GetFriendEmail=$data['E'.$i];
- $submission->write();
- //send email
- //$GetFriendName =$data['F'.$counter]; //change variable for sending in email
- $GetFriendEmail=$data['E'.$i];
- $From=$data['EmailFrom'];
- $To=$GetFriendEmail;
- $Subject=$this->Subject;
- $email= new Email($From, $To, $Subject);
- $email->setTemplate('FriendGetFriendEmail');
- //populate the email template and add message to the
- $EmailData = &$data; //copies data array into a new array
- $EmailData['name']=$data['FriendName'];
- $EmailData['GetFriendName']=$data['F'.$i];
- $EmailData['Message']=$this->Message;
- $EmailData['RegPage']=$this->RegPage;
- $EmailData['FMessage']=$data['FriendMessage'];
- $EmailData['counter']=$data['F'.$i];
- $email->populateTemplate($EmailData); //pass this array into the emailTemplate
- $email->send();
- //increment i
- $i++;
- //Redirects the success url
- Director::redirect(Director::baseURL(). $this->URLSegment."/?Success=1");
- }
- }
- public function Success(){
- //returns the user to the success url once the form has been submitted
- return isset($_REQUEST['Success']) && $_REQUEST['Success']== "1";
- }
- }
Add Comment
Please, Sign In to add comment