Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » How can I send a cutom form?

Our old forums are still available as a read-only archive.

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

Page: 1 2
Go to End
Author Topic: 4673 Views
  • cliersch
    Avatar
    Community Member
    75 Posts

    How can I send a cutom form? Link to this post

    I created a small form - but where and how do I have to implement the email adress and the send template!

    function Form() {
    return new Form($this, "Form", new FieldSet(
       new TextField("Name", "Name"),
       new EmailField("Email", "E-Mail:")
    ), new FieldSet(
    new FormAction("doform", "send")
    ));
    }
    function doform($data, $form) {
    }

    Please may anybody help me to understand how to send a form with an email.ss template? I could't get it from the tutorial.

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: How can I send a cutom form? Link to this post

    Hi there,

    Could you please clarify this a bit more so I can understand what you're after?

    Do you mean you want to send an email, using a template, once someone submits the form you've made?

    If so, you could do something like this:

    function doform($data, $form) {
       if(!empty($data['Email'])) {
          $email = new Email_Template(
             'fromemail@somewhere.com',
             $data['Email'],
             'Form was submitted - subject line (change me)'
          );
          $email->ss_template = 'MyEmailTemplate';
          $email->populateTemplate(array(
             'Name' => $data['Name'],
             'Email' => $data['Email']
          ));
          $email->send();
       }
    }

    Then, you would place MyEmailTemplate.ss, or whatever you have chosen into mysite/templates/email. the populateTemplate() call with an array means you can list in variables that you wish to be available in the template. In this example, $Name and $Email can be used in MyEmailTemplate.ss.

    Hope this makes sense.

    Cheers,
    Sean

  • cliersch
    Avatar
    Community Member
    75 Posts

    Re: How can I send a cutom form? Link to this post

    Thank you for the code example. I guess thats almost what I need. I try again to explain my problem, I try to install an contact form where the user can fill in his email an name and submit it to my e-mail adress (me@mysite.de) with these given data. (It should work like the UserDefined form - but I need to build it as a php function).
    Where do I have to put my email adress?
    And I guess I've got a problem with the "if(!empty($data['Email']) { " this ist putting out a

    Parse error: syntax error, unexpected '{'

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: How can I send a cutom form? Link to this post

    Hi there,

    The arguments to to the email class are:

    new Email_Template('from@email.com', 'to@email.com', 'Subject line');

    As for the parse error, there's a missing bracket I forgot to add. That line should instead read:

    if(!empty($data['Email'])) {

  • cliersch
    Avatar
    Community Member
    75 Posts

    Re: How can I send a cutom form? Link to this post

    Thanx Sean! I guess now I'm understanding better the logic an how these email forms will work!

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: How can I send a cutom form? Link to this post

    see http://doc.silverstripe.com/doku.php?id=email_template for a bit more info on emails

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: How can I send a cutom form? Link to this post

    willr: FYI, the Email_Template class is deprecated in sapphire/trunk. So, we'll need to update the wiki documentation for when we release 2.2.3.

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: How can I send a cutom form? Link to this post

    yea sweet as its just using Email now isnt it?. Versioning for the docs like jquery or cakephp is looking increasingly handy!

    4673 Views
Page: 1 2
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.