10379 Posts in 2194 Topics by 1710 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 801 Views |
-
[solved] Multiform email only sending data from last step

15 March 2011 at 2:28am
Hi all,
I have been working on this for some days but can't figure it out on my own.
Using the multiform module, I have 5 steps and the end results are to be emailed in one big email. The trouble I am having is all the data from setps 1,2,3 and 4 are being stored in the databse but its not included in the email, only the data from the last step is.
Here is the code;
<?php
class APMultiForm extends MultiForm {
public static $start_step = 'APPersonalDetailsFormStep';
public function finish($data, $form) {
parent::finish($data, $form);
$steps = DataObject::get('MultiFormStep', "SessionID = {$this->session->ID}");
$From = "website";
$To = "email";
$Subject = "Subject";
$email = new Email($From, $To, $Subject);
$email->setTemplate('AuPairEmail');
$email->populateTemplate($data);
$email->send();
Director::redirect(Director::baseURL(). $this->URLSegment . "terms-and-conditions");
}}
If I change any of the steps to be the last step, then the data from that step is emailed fine.
-
Re: [solved] Multiform email only sending data from last step

15 March 2011 at 9:46pm Last edited: 15 March 2011 9:46pm
From reading the documentation bundled with multiform (https://github.com/silverstripe/silverstripe-multiform) you may have to pull the data from each step manually. See the code snippet on that page...
$steps = DataObject::get('MultiFormStep', "SessionID = {$this->session->ID}");
if($steps) {
foreach($steps as $step) {
$data = $step->loadData();
}
} -
Re: [solved] Multiform email only sending data from last step

15 March 2011 at 10:51pm
Thanks for looking at this,
I have followed that tutorial to get the basic form working and that snippet has been included.
But I still cant get all the data into the email.
Here is the dump from the debug;Debug (APMultiForm->finish() in line 14 of APMultiForm.php)
* FirstName =
q
* Surname =
* Address =
...
Debug (APMultiForm->finish() in line 14 of APMultiForm.php)
* ChildName =
q
* ChildAge =
* ChildActivity =
* Baby =
0
...
Debug (APMultiForm->finish() in line 14 of APMultiForm.php)
* HouseType =
Detached
* Bedroom =
* Bathroom =
* CinemaDistance =
q
...
Debug (APMultiForm->finish() in line 14 of APMultiForm.php)* DateStart =
q
* Duration =
* APNat =
* action_finish =
Submit
The data is being pulled from the steps, but I can't figure out how to get all steps data included in the email.Is it someting to do with
$email->populateTemplate($data);
should it be something like$email->populateTemplate($step->loadData());
I have tried that and it wasn't the solution.Any ideas?
-
Re: [solved] Multiform email only sending data from last step

17 March 2011 at 5:25am
I have found a solution, it might not be elegant but it achives what i need.
<?php
class APMultiForm extends MultiForm {
public static $start_step = 'APStepOne';
public function finish($data, $form) {
parent::finish($data, $form);
$steps = DataObject::get('MultiFormStep', "SessionID = {$this->session->ID}");
if($steps) {
foreach($steps as $step) {
if($step->class == 'APStepOne') {
$dataone = $step->loadData(); }
if($step->class == 'APStepTwo') {
$datatwo = $step->loadData(); }
if($step->class == 'APStepThree') {
$datathree = $step->loadData(); }
if($step->class == 'APStepFour') {
$datafour = $step->loadData(); }
if($step->class == 'APStepFive') {
$datafive = $step->loadData(); }
//Debug::show($step->loadData());
}
}
$From = "xxx@xxx.com";
$To = "xxx@xxx.com";
$Subject = "xxxsubjectxxx";
$email = new Email($From, $To, $Subject);
$email->setTemplate('xxxtemplatexxx');
$email->populateTemplate($dataone);
$email->populateTemplate($datatwo);
$email->populateTemplate($datathree);
$email->populateTemplate($datafour);
$email->populateTemplate($datafive);
$email->send();
Director::redirect(Director::baseURL(). $this->URLSegment . "terms-and-conditions");
}}
-
Re: [solved] Multiform email only sending data from last step

17 March 2011 at 5:00pm
Why so many arrays? You could have 1 array then use array_merge to join the two (first thing that came to my head)
$output = array();
foreach($steps as $step) {
$output = array_merge($output, $step->loadData());
}..
$email->populateTemplate($output);I'm surprised that there isn't a method on MultiForm to do this automatically? Have you looked at the code?
| 801 Views | ||
|
Page:
1
|
Go to Top |


