I have a form that gets filled out and then on submit goes to a thank you page. That is the simple version.
The thing is...on the page previous to the form I have a url which, in its raw form, looks like this:
<a href="[[~14]]?pagetitle=[[*pagetitle]]&price=[[*price]]&carimage=[[*home-img]]&car_id=[[*id]]" class="info hover-bg">ARRANGE A VIEWING</a>
The page with this url is about one car (of many)...
14 is the ID of the page with the form on it. I am using the variables in the url to populate things on the form page such as the car they were looking at image, name and price...this works all fine.
My client has requested that on the thank you page, after the form has been submit, they still want to display all the same information.
The snippet is called on the form page. In the snippet I call a chunk that contains the form if the form !isset. If the form isset then take the details, email the client with the relevant info and then re-direct to the thank you page.
here is the script in its entirity:
ini_set('display_errors',1);
error_reporting(E_ALL);
$carId = $modx->runSnippet('getReqParam', array('name'=>'car_id'));
$carResource = $modx->getObject('modResource', $carId);
$title = $carResource->get('pagetitle');
$price = $carResource->getTVValue('price');
$img = $carResource->getTVValue('home-img');
$url = $modx->makeUrl(17,'web',array('pagetitle' => $title, 'price' => $price, 'carimage' => $img), 'full');
if(isset($_POST['view-submit']) || isset($_POST['drive-submit'])){
if(isset($_POST['view-submit'])){
$arrView = "This customer is coming to you";
}else if(isset($_POST['drive-submit'])){
$arrView = "The customer wants you to come to them";
}
$subjectline = 'Somebody would like to view a car!';
$emailfrom = '[email protected]';
$message = $modx->getChunk('viewingEmailTpl', array(
'name' => $_POST['viewer-name'],
'email' => $_POST['viewer-email'],
'mobile' => $_POST['viewer-phone'],
'car' => $_POST['viewer-car'],
'message' => $_POST['viewer-message'],
'burb' => $_POST['viewer-burb'],
'date' => $_POST['selected-date'],
'time' => $_POST['selected-time'],
'arrView' => $arrView
));
$modx->getService('mail', 'mail.modPHPMailer');
$modx->mail->set(modMail::MAIL_BODY,$message);
$modx->mail->set(modMail::MAIL_FROM,$emailfrom);
$modx->mail->set(modMail::MAIL_FROM_NAME,'Name');
$modx->mail->set(modMail::MAIL_SUBJECT,$subjectline);
$modx->mail->address('to','[email protected]');
$modx->mail->setHTML(true);
if (!$modx->mail->send()) {
$modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send the email: '.$modx->mail->mailer->ErrorInfo);
}
$modx->mail->reset();
$modx->sendRedirect($url);
}else{
$output = $modx->getChunk('arrViewForm');
}
return $output;
This script has changed quite a lot throughout the day but essentially that is what I have been trying to do.
Also, originally the $url var was just after the mail->reset() and I thought it being there could cause issues but moving it outside the if hasn't made any difference...although I kept it there just in case.
Hope this clears things up!
Thanks again for all the help! I really appreciate it! I have been pulling my hair out over this one haha...