I've setup a multiple step form process using the fantastic Multiform module. I've managed to work most of it out via the tutorial, but I'm a bit stuck with a few of the final steps.
So right now the user can go right through to the end of process, then 'Send order' for the final step. At this point I've got it so it will construct an HTML email with the data, but there's a few bits I'm not sure how to do:
1. Redirect the user to a page with a Success message
2. Attach a file to the email that has been uploaded via a FileField
Here is the code for the MultiForm subclass:
(FYI the form is online at http://dcsd.milestillinger.com/orders, but code may have changed by the time you look. With any luck, it'll be working...)
<?php
class BoardOrderMultiForm extends MultiForm {
protected static $start_step = 'BoardOrderAcceptTermsStep';
public function finish($data, $form) {
parent::finish($data, $form);
$body = "<h1>Online Order</h1>";
$steps = DataObject::get('MultiFormStep', "SessionID = {$this->session->ID}");
if($steps) {
foreach($steps as $step) {
$data = $step->loadData();
if($step->class == 'BoardOrderAcceptTermsStep') {
$data = $step->loadData();
if($data) {
}
}
if($step->class == 'BoardOrderShaping1Step') {
$data = $step->loadData();
if($data) {
$basic_type = $data['basic_type'];
$body .= "<h2>Shaping 1</h2>";
$body .= "<table style=\"width:500px;\"><tr>";
$body .= "<th>Basic type</th><td>" . $data['basic_type'] . "</td>";
$body .= "</tr><tr>";
$body .= "<th>Length</th><td>" . $data['length'] . "</td>";
$body .= "</tr><tr>";
$body .= "<th>Width</th><td>" . $data['width'] . "</td>";
$body .= "</tr><tr>";
$body .= "<th>Thickness</th><td>" . $data['thickness'] . "</td>";
$body .= "</tr></table>";
}
}
if($step->class == 'BoardOrderShaping2Step') {
$data = $step->loadData();
if($data) {
$body .= "<h2>Shaping 2</h2>";
$body .= "<table><tr>";
$body .= "<th>Rails type</th><td>" . $data['rails_type'] . "</td>";
$body .= "</tr><tr>";
$body .= "<th>Bottom shape</th><td>" . $data['bottom_shape'] . "</td>";
$body .= "</tr><tr>";
$body .= "<th>Bottom shape (other)</th><td>" . $data['bottom_shape_other'] . "</td>";
$body .= "</tr><tr>";
$body .= "<th>Tail shape</th><td>" . $data['tail_shape'] . "</td>";
$body .= "</tr><tr>";
$body .= "<th>Tail shape (other)</th><td>" . $data['tail_shape_other'] . "</td>";
$body .= "</tr><tr>";
$body .= "</dl>";
}
}
if($step->class == 'BoardOrderFinal') {
$data = $step->loadData();
if($data) {
}
}
Debug::show($step->loadData()); // Shows the step data (unserialized by loadData)
}
}
// Get email address from page or send to admin
$sendto = ($this->ContactEmail!='' ? $this->ContactEmail : Email::getAdminEmail());
// Send email to Item Contact
$email = new Email('blah@gmail.com', 'blah@gmail.com', "Website Order: " . $basic_type, $body);
$email->send();
//Director::redirect("orders");
//$response = array("Success" => "Success");
// Send email to User who enquired
//$email = new Email('blah@gmail.com', $data['email'], 'Receipt of website enquiry from Chapman Surfboards: '.$data['Title'], "Thankyou for your enquiry.\n\n".$body);
//$email->sendPlain();
//$this->customise($response)->renderWith(array('Page', 'Page'));
}
}
?>
And here's the output of the Debug once the order has been sent:
Debug (BoardOrderMultiForm->finish() in line 68 of BoardOrderMultiForm.php)
* terms_accepted =
1
Debug (BoardOrderMultiForm->finish() in line 68 of BoardOrderMultiForm.php)
* basic_type =
shortboard
* length =
6'1"
* width =
18 0"
* thickness =
2 1/2"
Debug (BoardOrderMultiForm->finish() in line 68 of BoardOrderMultiForm.php)
* rails_type =
mid
* bottom_shape =
single_double
* bottom_shape_other =
* tail_shape =
Round tail
* tail_shape_other =
Debug (BoardOrderMultiForm->finish() in line 68 of BoardOrderMultiForm.php)
* glassing =
Strong (6-6 x 4)
* fins =
M3
* fins_other =
* finish =
Sanded Polish
* decals_colour =
Blue & Black
* spray_info =
* MAX_FILE_SIZE =
31457280
* spray =
o name =
phil-roberts.jpg
o type =
image/jpeg
o tmp_name =
/tmp/php2yJINC
o error =
0
o size =
1262144
Debug (BoardOrderMultiForm->finish() in line 68 of BoardOrderMultiForm.php)
* extra_shaping =
Single wing
* channels =
4
* extra_info =
asdfasdf
Debug (BoardOrderMultiForm->finish() in line 68 of BoardOrderMultiForm.php)
* rocker =
Average
* nose_rocker =
* tail_rocker =
* nose_width =
Leave to shaper
* tail_width =
Leave to shaper
Debug (BoardOrderMultiForm->finish() in line 68 of BoardOrderMultiForm.php)
* name =
Testing by Miles
* email =
blah@mailinator.com
* home_phone =
234234
* mobile =
234234
* street_address =
asdfasdf
* suburb =
sdfasdf
* postcode =
23422
* country =
AU
* height =
* weight =
* pickup_date =
o date =
17
o month =
10
o year =
2008
Debug (BoardOrderMultiForm->finish() in line 68 of BoardOrderMultiForm.php)