17488 Posts in 4473 Topics by 1978 members
| Go to End | Next > | |
| Author | Topic: | 4463 Views |
-
How can I send a cutom form?

4 July 2008 at 10:03pm Last edited: 5 July 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.
-
Re: How can I send a cutom form?

4 July 2008 at 11:24pm Last edited: 5 July 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 -
Re: How can I send a cutom form?

5 July 2008 at 12:18am Last edited: 5 July 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 aParse error: syntax error, unexpected '{'
-
Re: How can I send a cutom form?

5 July 2008 at 10:40am Last edited: 5 July 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'])) {
-
Re: How can I send a cutom form?

5 July 2008 at 10:52am
Thanx Sean! I guess now I'm understanding better the logic an how these email forms will work!
-
Re: How can I send a cutom form?

6 July 2008 at 1:20pm
see http://doc.silverstripe.com/doku.php?id=email_template for a bit more info on emails
-
Re: How can I send a cutom form?

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.
-
Re: How can I send a cutom form?

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!
| 4463 Views | ||
| Go to Top | Next > |



