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.

Archive /

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

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

How can I send a cutom form?


Go to End


14 Posts   5902 Views

Avatar
cliersch

Community Member, 75 Posts

8 July 2008 at 3:46am

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

Administrator, 690 Posts

14 July 2008 at 5:42pm

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

Community Member, 34 Posts

14 July 2008 at 10:24pm

Edited: 15/07/2008 1:49am

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?

Avatar
Willr

Forum Moderator, 5523 Posts

15 July 2008 at 9:24am

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

Avatar
cliersch

Community Member, 75 Posts

15 July 2008 at 7:48pm

Edited: 15/07/2008 9:14pm

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

Community Member, 9 Posts

9 September 2008 at 1:12am

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

Go to Top