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: 4676 Views
  • cliersch
    Avatar
    Community Member
    75 Posts

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

    Sorry - bu my Contact form isn't working. I receive no mails.
    I build in this code:

    function Form() {
    return new Form($this, "Form", new FieldSet(
    new TextField("Name", "Name"),
        new EmailField("Email", "E-Mail:"),
        new FieldSet(
    new FormAction("doform", "abschicken")
    ), new RequiredFields( "", ""
    ));
    }
    function doform($data, $form) {
          $email = new Email_Template(
             'user@user.de',
             'me@mysite.com',
             'Contact form'
          );
          $email->ss_template = 'Contact';
          $email->populateTemplate(array(
             'Name' => $data['Name'],
             'Email' => $data['Email'],
          ));
          $email->send();
    }   

    I use also a Contact.ss. Are there any errors? How can I give an "OnComplete" message to the user?

  • Sam
    Avatar
    Administrator
    679 Posts

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

    Perhaps this is because server's email configuration has issues. If you create a simple PHP function that just calls "mail('to@example.com', 'subject', 'body');" and visit it, does it send an email?

  • cerelac
    Avatar
    Community Member
    34 Posts

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

    Hi everyone.

    I would like to know if it's possible to change the "The following data was submitted to your website:" message, when the data collected from the form is sent by e-mail.

    I've already looked at email templates page and tried to use tiga's code but I can't get it to work.

    EDIT: I've changed the message in cms/templates/email/SubmittedFormEmail.ss and it worked.

    PS: What does the _t() function do?

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

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

    the _t function is the SilverStripe translator function - http://doc.silverstripe.com/doku.php?id=i18n

  • cliersch
    Avatar
    Community Member
    75 Posts

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

    My contact form is working perfectly. I created this code:

    class Page_Controller extends ContentController {
       function MyForm() {
    $fields = new FieldSet(
    new TextField("Name", "Name:"),
    new EmailField("Email", "E-Mail:")
    );
        $validator = new RequiredFields('Name', 'Email',);
    $actions = new FieldSet(
    new FormAction('doMyForm', 'send')
    );
    return new Form($this, 'MyForm', $fields, $actions, $validator);
    }
    function doMyForm($data, $form) {
        $email = new Email_Template(
       $data['Email'],
       'to_me@mysite.com',
       'This is your e-mail subject!'
    );
    $email->ss_template = 'Contact'; // Please create templates/email/Contact.ss
    $email->populateTemplate(array(
           'Name' => $data['Name'],
    'Email' => $data['Email'],
    ));
    $email->send();
    Director::redirect("Thanks_for_sending/"); // jumps to site you want to display after sending
    }
    }

    You may create this file templates/email/Contact.ss witch will contain all information ($Name, $Email) and send by email to.
    I also created a new page in SS called "Thanks_for_sending" and put this content in it. This works perfectly if you don't need other languages.   

  • bird
    Avatar
    Community Member
    9 Posts

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

    Hi tiga,

    tried to use your custom contact form but it doesn't work for me!?
    There is one "," too much in the validator listing but that's not the problem...maybe you can post your contac.ss so I can see, what's wrong!? I call the $myFrom and everything (except the validator-language) works fine but I receive no mails!? <mail> function and inbox work!

    Thanks
    Bernhard

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