1998 Posts in 530 Topics by 433 members
E-Commerce Modules
SilverStripe Forums » E-Commerce Modules » [SOLVED] Custom Form productpage needs to send Title of product with e-mail
Discuss about the various e-commerce modules available:
Ecommerce, SS Shop, SilverCart and SwipeStripe
Alternatively, have a look the shared mailinglist.
Moderators: martimiz, Nicolaas, Howard, Sean, Ryan M., biapar, Willr, Ingo, Jedateach, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 670 Views |
-
[SOLVED] Custom Form productpage needs to send Title of product with e-mail

28 October 2011 at 9:36pm
Hello,
I have edited product.php and added a simple contact form from ssbits.com, so on every product page there is a contact form.
The only problem is that i want the product title (and mayby some other variables like price etc) to send with the e-mail.
Im trying this by adding the product title to the value of a textfield and sending this textfield with the email.
The fields are sending the data that is inserted, expect the variable title(its not showing in the textfield). I dont really know how to add this variable to the form/data. Any help would be great.Here is the code that I've added to product.php:
class Product_Controller extends Page_Controller {
static $allowed_actions = array(
'ReageerForm'
);function ReageerForm() {
// Create fields
$fields = new FieldSet(
new TextField('Title', 'Title', $value = $Title),
new TextField('Bedrijfsnaam', 'Bedrijfsnaam'),
new TextField('Naam', 'Naam'),
new EmailField('Email', 'Email'),
new TextField('Telefoon', 'Telefoon'),
new TextField('Onderwerp', 'Onderwerp'),
new TextareaField('Bericht','Bericht')
);// Create action
$actions = new FieldSet(
new FormAction('SendReageerForm', 'Verzenden')
);// Create Validators
$validator = new RequiredFields('Naam', 'Telefoon', 'Onderwerp', 'Bericht', 'Email');return new Form($this, 'ReageerForm', $fields, $actions, $validator);
}
function SendReageerForm($data, $form, $title) {//Set data
$From = $data['Email'];
$To = $this->Mailto;
$To = "test@test.nl";
$Subject = "Reactie Product";
$email = new Email($From, $To, $Subject);
//set template
$email->setTemplate('reageerEmail');
//populate template
$email->populateTemplate($data);
//send mail
$email->send();
//return to submitted message
Director::redirect($this->Link("?success=1"));
}Thank you in advance for the help you can provide.
-
Re: [SOLVED] Custom Form productpage needs to send Title of product with e-mail

29 October 2011 at 10:38am
Hi JanJan - welcome to the forum.
The way that usually solve this is by using a hidden field in the form like this:
function ContactForm() {
if($currentPage = DataObject::get_by_id("SiteTree", $this->ID)){
$fields = new FieldSet(
new TextField('Name'),
new EmailField('Email'),
new TextareaField('Message'),
new HiddenField ('Page', 'Page',
$currentPage->Title
)
);
$actions = new FieldSet( new FormAction('doContactForm', 'Submit'));
$validator = new RequiredFields('Email', 'Message');return new Form($this, 'ContactForm', $fields, $actions, $validator);
}}Then in your email template you can just use $Page to display the title of the page that the form was displayed on.
Does that help?
-
Re: [SOLVED] Custom Form productpage needs to send Title of product with e-mail

2 November 2011 at 12:13am
Hi Howard,
Thank you for your quick reply!
The information you have provided me was enough and has helped me to solve my problem.
The if($currenpage) statement is what i needed for my contact form.Thank you again for you help!
| 670 Views | ||
|
Page:
1
|
Go to Top |

