We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 48659
    • 1 Posts
    I have been working on creating a webpage when clicked, will take them to the page where users have already submitted their personal information (form with first &last name, email, contact phone, zip code and square footage of house) but not have gone through with the purchase of product.
    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.
      • 3749
      • 24,544 Posts
      If you have code that processes their previous form submission you can set one or more $_SESSION variables with the values. Then you can read those variables anywhere as long as they're still on line.

      $_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.



        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting