Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

FORMS


Reply


2 Posts   662 Views

Avatar
Lydia

Community Member, 6 Posts

22 October 2009 at 11:41am

Hi All,

I have been trying to work this out for a very long time now with no success....

I've got a business listing page set up right... and it has a list of details... on the listing page it has two different email addresses.. $Email1 and $Email2.

When you click on the link for $Email1 or $Email2 it takes you to a contact page with the ID passed to the contact page

I then want to get $Email1 and send the contact form to that email address... here is the code I have set up:

class ContactListing_Controller extends Page_Controller {
   
   public function getEmail() {
         $ea = $_REQUEST['id'];
         $email = DataObject::get_by_id("BusinessListing", "$ea");
         $emailTo = $email->Email1;
         Debug::show($emailTo);
if(!$email) return false;

      }
      
   public function ContactListingForm() {
         $ea = $_REQUEST['id'];
         $email = DataObject::get_by_id("BusinessListing", "$ea");
         $emailTo = $email->Email1;
      
      return new Form($this, "ContactListingForm", new FieldSet(
         
         new TextField("Name"),
         new TextField("Phone"),
         new TextField("Email", "Email"),
         new TextareaField("Comment"),
         new TextField("MyEmail", "MyEmail", "$emailTo")
         

      ), new FieldSet(
         
         new FormAction("ContactListingAction", "Submit")

      ), new RequiredFields());
   }
   
   public function ContactListingAction($data, $form) {
      
         
         $from = 'example@email.com';
         $to = $data['MyEmail'];
         $subject = 'testing for website 9';
         $body = 'This is the body of my email';
         
         
         $email = new Email();
         $email->setTemplate('ContactListing_Email');
         $email->setFrom($from);
         $email->setTo($to);
         $email->setSubject($subject);
   
         $email->populateTemplate($data);
         
         $email->send();
      
      Director::redirect('contact-listing/success');
      
   }
   

}

The error I get is Undefined index: id

I know that this is because I am essentially trying to POST the id and it's not being passed through the form...

please help!!!

Avatar
dalesaurus

Community Member, 283 Posts

23 October 2009 at 4:23pm

SS has abstracted the old school PHP $_REQUEST variable. You will want to access variables in the $this->URLParams variable which will fetch it off the URL.