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   5903 Views

Avatar
cliersch

Community Member, 75 Posts

4 July 2008 at 10:03pm

Edited: 05/07/2008 12:29am

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.

Avatar
Sean

Forum Moderator, 922 Posts

4 July 2008 at 11:24pm

Edited: 05/07/2008 10:45am

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

Avatar
cliersch

Community Member, 75 Posts

5 July 2008 at 12:18am

Edited: 05/07/2008 12:29am

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 '{' 

Avatar
Sean

Forum Moderator, 922 Posts

5 July 2008 at 10:40am

Edited: 05/07/2008 10:41am

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'])) {

Avatar
cliersch

Community Member, 75 Posts

5 July 2008 at 10:52am

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

Avatar
Willr

Forum Moderator, 5523 Posts

6 July 2008 at 1:20pm

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

Avatar
Sean

Forum Moderator, 922 Posts

6 July 2008 at 2:10pm

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.

Avatar
Willr

Forum Moderator, 5523 Posts

6 July 2008 at 3:58pm

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

Go to Top