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.

Archive

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

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

How can I send a cutom form?


Reply

14 Posts   4779 Views

Avatar
cliersch

8 July 2008 at 3:46am Community Member, 75 Posts

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?

Avatar
Sam

14 July 2008 at 5:42pm Administrator, 685 Posts

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?

Avatar
cerelac

14 July 2008 at 10:24pm (Last edited: 15 July 2008 1:49am), Community Member, 34 Posts

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 [url=http://doc.silverstripe.com/doku.php?id=email_template]email templates page[/url] 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?

Avatar
Willr

15 July 2008 at 9:24am Forum Moderator, 5511 Posts

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

Avatar
cliersch

15 July 2008 at 7:48pm (Last edited: 15 July 2008 9:14pm), Community Member, 75 Posts

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.   

Avatar
bird

9 September 2008 at 1:12am Community Member, 9 Posts

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