Jump to:

23483 Posts in 18976 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » FORMS

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

Page: 1
Go to End
Author Topic: 634 Views
  • Lydia
    Avatar
    Community Member
    6 Posts

    FORMS Link to this post

    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!!!

  • dalesaurus
    Avatar
    Community Member
    283 Posts

    Re: FORMS Link to this post

    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.

    634 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.