Jump to:

2002 Posts in 1422 Topics by 616 members

Form Questions

SilverStripe Forums » Form Questions » Returning current page in email about submitted form

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

Page: 1
Go to End
Author Topic: 1319 Views
  • Howard
    Avatar
    Community Member
    215 Posts

    Returning current page in email about submitted form Link to this post

    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();
    }

  • Howard
    Avatar
    Community Member
    215 Posts

    Re: Returning current page in email about submitted form Link to this post

    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();
    }

  • bebabeba
    Avatar
    Community Member
    192 Posts

    Re: Returning current page in email about submitted form Link to this post

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

    1319 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.