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