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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Form Questions /

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

Returning current page in email about submitted form


Go to End


3 Posts   2179 Views

Avatar
Howard

Community Member, 215 Posts

25 January 2009 at 10:08pm

Hi guys, I have a simple form which appears on every product page of a site, I would like it so that when the form is submitted the title of the page on which the form is submitted from appears in the email. How can this be done? Here is the current code for the form. Thanks in advance for any help!

	 function ContactForm() {
      // Create fields
      $fields = new FieldSet(
         new EmailField('Email'),
         new TextareaField('Message')
      );
 
      // Create actions
      $actions = new FieldSet(
         new FormAction('doContact', 'Submit')
      );
 $validator = new RequiredFields('Email', 'Message');
        return new Form($this, 'ContactForm', $fields, $actions, $validator);
   }

 
 function doContact($data, $form) {
      $email = new Email();
      $email->setTemplate('ContactPage_Email');
      $email->setSubject('Someone submitted the contact form');
      $email->setFrom('admin@somesite.com');
      $email->setTo('howardgrigg@gmail.com');
      $email->populateTemplate($data);
      $email->send();

      $form->sessionMessage('Thanks for contacting us. We will endeavour to get in touch with you as soon as possible!', 'good'); 
	
      Director::redirectBack();
   }

Avatar
Howard

Community Member, 215 Posts

25 January 2009 at 11:30pm

Hey, thanks to ajshort in the IRC chatroom I have got this working, I just needed to pass the Title into the data array and then call it in the email template. The new code is posted below:

function doContact($data, $form) {
     $data['PageName'] = $this->Title;
	
	  $email = new Email();
      $email->setTemplate('ContactPage_Email');
      $email->setSubject('Someone submitted the contact form');
      $email->setFrom('admin@jdmnz.com');
      $email->setTo('howardgrigg@gmail.com');
      $email->populateTemplate($data);
      $email->send();

      $form->sessionMessage('Thanks for contacting us. We will endeavour to get in touch with you as soon as possible!', 'good'); 
	
      Director::redirectBack();
   }

Avatar
bebabeba

Community Member, 193 Posts

5 February 2009 at 10:41pm

Hi!
I read your post, I have a question for you.
I have a problem if I send data schoose from checkboxsetField. I have this error:

ArrayData::__construct: Parameter needs to be an object or associative array
At line 39 in E:\_silverstripe_cms\silverstripe\sapphire\core\ArrayData.php

new CheckboxSetField(
$name = "topics",
$title = "Settori d'interesse:",
$source = array(
"1" => "Information Management",
"2" => "Application Integration (EAI)",
"3" => "System Management",
),
$value = ""
)

and in GenericEmail.ss I wrote: Settori d'interesse: $topics

Have you idea how solve this?
Thanks!!