<![CDATA[ How to send an email with link for purchasing from previously stored form submitted - My Forums]]> https://forums.modx.com/thread/?thread=92826 <![CDATA[How to send an email with link for purchasing from previously stored form submitted]]> https://forums.modx.com/thread/92826/how-to-send-an-email-with-link-for-purchasing-from-previously-stored-form-submitted#dis-post-507199 Created a working snippet as shown below that allows me to store the user information for creating a lead.

<?php
$arr = array_merge($_GET, $_POST);
foreach($arr as $key=>$value)
$arr[$key] = mysql_escape_string($value);
if(!$arr['firstname'] || !$arr['lastname'] || !$arr['email'])
return;
if(!$arr['id']) {
$qry = 'SELECT id FROM modx_kate_userData WHERE email="' . $arr['email'] . '" AND userid=0';
//echo $qry;
$result = $modx->query($qry);
if(is_object($result)) $data = $result->fetchAll(PDO::FETCH_ASSOC);
if(sizeof($data))
$arr['id'] = $data[0]['id'];
}
if($arr['id']) {
//echo 'UPDATE modx_kate_userData SET firstname="' . $arr['firstname'] . '", lastname="' . $arr['lastname'] . '", email="' . $arr['email'] .'", phone="' . $arr['phone'] .'", sqfootage="' . $arr['sqfootage'] .'", updatedon=NOW() WHERE id=' . $arr['id'];exit;
$stmt = $modx->prepare('UPDATE modx_kate_userData SET firstname="' . $arr['firstname'] . '", lastname="' . $arr['lastname'] . '", secondary_name="' . $arr['secondary_name'] . '", email="' . $arr['email'] .'", phone="' . $arr['phone'] .'", sqfootage="' . $arr['sqfootage'] .'", sweepstakecode="' . $arr['sweepstakecode'] . '", updatedon=NOW() WHERE id=' . $arr['id']);
$stmt->execute();
return $arr['id'];
}
else {
$qry = 'SELECT d.id, d.firstname, d.lastname, d.salesid, u.username, u.primary_group, mg.id, mg.user_group, mg.member, mg.role FROM modx_kate_userData d LEFT JOIN modx_users u ON d.salesid=u.id LEFT JOIN modx_member_groups mg ON mg.member=u.id WHERE mg.role=6 ORDER BY d.id DESC LIMIT 1';
//echo $qry;
$result = $modx->query($qry);
if(is_object($result)) $data = $result->fetchAll(PDO::FETCH_ASSOC);
if(sizeof($data))
$lastSalesID = $data[0]['salesid'];

$qry = "SELECT u.username, u.primary_group, mg.user_group, mg.member AS id, mg.role FROM modx_users u LEFT JOIN modx_member_groups mg ON mg.member=u.id WHERE mg.role=6 ORDER BY u.id";
//echo $qry;
$result = $modx->query($qry);
if(is_object($result)) $data = $result->fetchAll(PDO::FETCH_ASSOC);
$salesid = 0;
if($arr['debug']) print_r($data);
if(sizeof($data))
foreach($data as $key=>$datum) {
if($datum['id']==$lastSalesID)
$salesid = $data[$key+1]['id'];
}
if(!$salesid) $salesid = $data[0]['id'];

//echo 'INSERT INTO modx_kate_userData(firstname, lastname, email, phone, zip, sqfootage, salesid, sweepstakecode, notes, source, createdon, updatedon) VALUES("' . $arr['firstname'] . '", "' . $arr['lastname'] . '", "' . $arr['email'] .'", "' . $arr['phone'] .'", "' . $arr['zip'] .'", "' . $arr['sqfootage'] .'", ' . $salesid . ', "' . $arr['sweepstakecode'] . '", "' . $arr['notes'] . '", "' . $arr['source'] . '", NOW(), NOW())';
$stmt = $modx->prepare('INSERT INTO modx_kate_userData(firstname, lastname, secondary_name, email, phone, zip, sqfootage, salesid, sweepstakecode, notes, source, createdon, updatedon) VALUES("' . $arr['firstname'] . '", "' . $arr['lastname'] . '", "' . $arr['secondary_name'] .'", "' . $arr['email'] .'", "' . $arr['phone'] .'", "' . $arr['zip'] .'", "' . $arr['sqfootage'] .'", ' . $salesid . ', "' . $arr['sweepstakecode'] . '", "' . $arr['notes'] . '", "' . $arr['source'] . '", NOW(), NOW())');
$stmt->execute();
$qry = 'SELECT id FROM modx_kate_userData WHERE email="' . $arr['email'] . '" AND userid=0';
//echo $qry;exit;
$result = $modx->query($qry);
if(is_object($result)) $data = $result->fetchAll(PDO::FETCH_ASSOC);
return $data[0]['id'];
}

However, I am really stuck on using the email ID information from their previous form submission to be used for sending them an email with a link to give them another chance to buy the product again without re-entering the form with personal information again.(There is no log in required). Any kind of help is appreciated.]]>
katenaomi Aug 24, 2014, 04:19 PM https://forums.modx.com/thread/92826/how-to-send-an-email-with-link-for-purchasing-from-previously-stored-form-submitted#dis-post-507199
<![CDATA[Re: How to send an email with link for purchasing from previously stored form submitted]]> https://forums.modx.com/thread/92826/how-to-send-an-email-with-link-for-purchasing-from-previously-stored-form-submitted#dis-post-507201
$_SESSION['id'] = $id;


And later,

$id = $_SESION['id'];


If you need them later, after the user is gone, you'd have to save them to a file named in some way that identifies the user.



]]>
BobRay Aug 24, 2014, 05:05 PM https://forums.modx.com/thread/92826/how-to-send-an-email-with-link-for-purchasing-from-previously-stored-form-submitted#dis-post-507201