<form action="[[~236]]" method="post">
<label for="name">Name</label>
<input type="text" name="name" id="name" required value="[[+name]]" />
<label for="company">Company</label>
<input type="text" name="company" id="company" required value="[[+company]]" />
<label for="address">Address</label>
<input type="text" name="address" id="address" required value="[[+address]]" />
<label for="city">City</label>
<input type="text" name="city" id="city" required value="[[+city]]" />
<label for="postcode">Post code</label>
<input type="text" name="postcode" id="postcode" maxlength="10" required value="[[+postcode]]" />
<button class="btn" type="submit" name="submit" />Get Quote</button>
</form>
This question has been answered by lkfranklin. See the first response.
What are you using to pull in the users fields? profile, personalise or a custom snippet?
// Get posted variables $name = $profile->fullname; $company = $profile->company; $address = $profile->address; $city = $profile->city; $postcode = $profile->zip; $country = $profile->country; $email = $profile->email; $phone = $profile->phone;
$profile = $modx->user->getOne('Profile');
$extended = $profile->get('extended');
echo $extended['company'];
Yeah the extended fields are stored as json elsewhere.
<!--?php $extended = $profile--->get('extended'); echo $extended['company'];
$profile = $modx->user->getOne('Profile');
$extended = $profile->get('extended');
echo $extended['company'];
Sorry forgot to define $profile at the top of my code.
$profile = $modx->user->getOne('Profile'); $extended = $profile->get('extended'); echo $extended['company'];

<?php
session_start();
$output = '';
$items = '';
$basket_total = 0;
$errors = array();
$success = array();
//---------------------------------------------------------------
// Get user profile if they are logged in
$user = $modx->getUser();
$profile = $user->getOne('Profile');
//-- ADDITIONAL CODE ADDED 10.05.18 - NOT WORKING
$profile = $modx->user->getOne('Profile');
$extended = $profile->get('extended');
echo $extended['company'];
//-- ADDITIONAL CODE ADDED 10.05.18 - NOT WORKING
// Get posted variables
$name = $profile->fullname;
//$company = $profile->company;
$address = $profile->address;
$city = $profile->city;
$postcode = $profile->zip;
$country = $profile->country;
$email = $profile->email;
$phone = $profile->phone;
//---------------------------------------------------------------
$basket = $_SESSION['basket'];
foreach ($basket as $key => $item) {
$items .= $modx->getChunk('duraflex.quote.row', $item);
$basket_total += $item['quantity'] * $item['price'];
}
//---------------------------------------------------------------
if (isset($_POST['submit'])) {
// Get posted variables
$name = $_POST['name'];
$company = $_POST['company'];
$address = $_POST['address'];
$city = $_POST['city'];
$postcode = $_POST['postcode'];
$country = $_POST['country'];
$email = $_POST['email'];
$phone = $_POST['phone'];
// Get MODX settings
$to = '[email protected]'; //$modx->getOption('emailsender');
$from = $modx->getOption('emailsender');
$site_name = $modx->getOption('site_name');
$subject = "Duraflex: Quote request by $name";
$message = $modx->getChunk('duraflex.quote.email', array(
'items' => $items,
'name' => $name,
'company' => $company,
'address' => $address,
'city' => $city,
'postcode' => $postcode,
'country' => $country,
'email' => $email,
'phone' => $phone,
));
// Send email: TODO
$modx->getService('mail', 'mail.modPHPMailer');
$modx->mail->reset();
$modx->mail->set(modMail::MAIL_BODY, $message);
$modx->mail->set(modMail::MAIL_FROM, $from);
$modx->mail->set(modMail::MAIL_FROM_NAME, $site_name);
$modx->mail->set(modMail::MAIL_SENDER, $from);
$modx->mail->set(modMail::MAIL_SUBJECT, $subject);
$modx->mail->address('to', $to);
$modx->mail->address('to', '[email protected]');
$modx->mail->setHTML(true);
if (!$modx->mail->send()) {
$modx->log(modX::LOG_LEVEL_ERROR,'[FormIt] An error occurred while trying to send the email: '.$modx->mail->mailer->ErrorInfo);
return false;
}
$modx->mail->reset();
$output = $modx->getChunk('duraflex.quote.confirmation', array(
'title' => $title,
'errors' => implode('</li><li>', $errors),
'success' => implode('</li><li>', $success),
'items' => $items,
'name' => $name,
'company' => $company,
'address' => $address,
'city' => $city,
'postcode' => $postcode,
'country' => $country,
'email' => $email,
'phone' => $phone,
));
// Save to user account if applicable
if ($user = $modx->getUser()) {
// Save their order to the database
if ($modx->addPackage('duraflex', MODX_CORE_PATH . 'components/duraflex/model/', 'me')) {
$order = $modx->newObject('Duraflex');
$order->set('userid', $user->get('id'));
$order->set('status', 'new');
$order->set('orderdate', date("Y-m-d H:i:s"));
$order->set('data', json_encode($basket));
$order->save();
}
// Update user profile with the details they entered?
// if ($profile = $modx->getObject('modUserProfile', array('internalKey' => $id))) {
// $fullname = $profile->get('fullname');
// }
}
// Destroy basket
unset($_SESSION['basket']);
} else {
$output = $modx->getChunk('duraflex.quote', array(
'title' => $title,
'errors' => implode('</li><li>', $errors),
'success' => implode('</li><li>', $success),
'items' => $items,
'name' => $name,
'company' => $company,
'address' => $address,
'city' => $city,
'postcode' => $postcode,
'country' => $country,
'email' => $email,
'phone' => $phone,
'basket_total' => $basket_total,
));
}
return $output;
// Get posted variables $name = $profile->fullname; $company = $extended['company']; $address = $profile->address; $city = $profile->city; $postcode = $profile->zip; $country = $profile->country; $email = $profile->email; $phone = $profile->phone;
<?php
session_start();
$output = '';
$items = '';
$basket_total = 0;
$errors = array();
$success = array();
//---------------------------------------------------------------
// Get user profile if they are logged in
$user = $modx->getUser();
$profile = $user->getOne('Profile');
//-- ADDITIONAL CODE ADDED 10.05.18 - NOT WORKING
/*$profile = $modx->user->getOne('Profile');*/
$extended = $profile->get('extended');
echo $extended['company'];
//-- ADDITIONAL CODE ADDED 10.05.18 - NOT WORKING
// Get posted variables
$name = $profile->fullname;
$company = $extended['company'];
//$company = $profile->company;
$address = $profile->address;
$city = $profile->city;
$postcode = $profile->zip;
$country = $profile->country;
$email = $profile->email;
$phone = $profile->phone;
//---------------------------------------------------------------
$basket = $_SESSION['basket'];
foreach ($basket as $key => $item) {
$items .= $modx->getChunk('duraflex.quote.row', $item);
$basket_total += $item['quantity'] * $item['price'];
}
//---------------------------------------------------------------
if (isset($_POST['submit'])) {
// Get posted variables
$name = $_POST['name'];
/*$company = $_POST['company'];*/
$company = $extended['company'];
$address = $_POST['address'];
$city = $_POST['city'];
$postcode = $_POST['postcode'];
$country = $_POST['country'];
$email = $_POST['email'];
$phone = $_POST['phone'];
// Get MODX settings
$to = '[email protected]'; //$modx->getOption('emailsender');
$from = $modx->getOption('emailsender');
$site_name = $modx->getOption('site_name');
$subject = "Duraflex: Quote request by $name";
$message = $modx->getChunk('duraflex.quote.email', array(
'items' => $items,
'name' => $name,
'company' => $company,
'address' => $address,
'city' => $city,
'postcode' => $postcode,
'country' => $country,
'email' => $email,
'phone' => $phone,
));
// Send email: TODO
$modx->getService('mail', 'mail.modPHPMailer');
$modx->mail->reset();
$modx->mail->set(modMail::MAIL_BODY, $message);
$modx->mail->set(modMail::MAIL_FROM, $from);
$modx->mail->set(modMail::MAIL_FROM_NAME, $site_name);
$modx->mail->set(modMail::MAIL_SENDER, $from);
$modx->mail->set(modMail::MAIL_SUBJECT, $subject);
$modx->mail->address('to', $to);
$modx->mail->address('to', '[email protected]');
$modx->mail->setHTML(true);
if (!$modx->mail->send()) {
$modx->log(modX::LOG_LEVEL_ERROR,'[FormIt] An error occurred while trying to send the email: '.$modx->mail->mailer->ErrorInfo);
return false;
}
$modx->mail->reset();
$output = $modx->getChunk('duraflex.quote.confirmation', array(
'title' => $title,
'errors' => implode('</li><li>', $errors),
'success' => implode('</li><li>', $success),
'items' => $items,
'name' => $name,
'company' => $company,
'address' => $address,
'city' => $city,
'postcode' => $postcode,
'country' => $country,
'email' => $email,
'phone' => $phone,
));
// Save to user account if applicable
if ($user = $modx->getUser()) {
// Save their order to the database
if ($modx->addPackage('duraflex', MODX_CORE_PATH . 'components/duraflex/model/', 'me')) {
$order = $modx->newObject('Duraflex');
$order->set('userid', $user->get('id'));
$order->set('status', 'new');
$order->set('orderdate', date("Y-m-d H:i:s"));
$order->set('data', json_encode($basket));
$order->save();
}
// Update user profile with the details they entered?
// if ($profile = $modx->getObject('modUserProfile', array('internalKey' => $id))) {
// $fullname = $profile->get('fullname');
// }
}
// Destroy basket
unset($_SESSION['basket']);
} else {
$output = $modx->getChunk('duraflex.quote', array(
'title' => $title,
'errors' => implode('</li><li>', $errors),
'success' => implode('</li><li>', $success),
'items' => $items,
'name' => $name,
'company' => $company,
'address' => $address,
'city' => $city,
'postcode' => $postcode,
'country' => $country,
'email' => $email,
'phone' => $phone,
'basket_total' => $basket_total,
));
}
return $output;