Newsletter Plugin.

By Toledoh - December 9, 2012

Hi Guys,

Is there a way to add additional capture fields to the newsletter plugin? ie. name, company etc?) I just want to capture those fields at present, but later on as the plugin matures, I'd like to be able in include ##name## etc as a placeholder in the emails.
Cheers,

Tim (toledoh.com.au)

Re: [Toledoh] Newsletter Plugin.

Hi Tim,

You can store additional user data by adding as many additional fields to the _nlb_subscribers table as you require, and this will have no affect on the plugin.

If you're using a newsletter subscription form on your site, you can generate a form using the following steps:

1)In your admin area go to the plugins section, then select the code generator link for the newsletter builder plugin. You can use this code to create your basic subscription form, and add any additional fields that you require. You will also need to change the name of the hidden field submitForm to something else to stop the newsletterBuilder plugin handling the form submission. In this example I've changed it to submitFormCustom.

2)Next you will need to create your own custom form submission code, if you copy the code that deals with form submissions from newsletterBuilder.php around line 708 to 748 and add it to the top of your signup page, then you will need to modify the code to store the additional fields into the subscribers table, I've created an example of this below:

<?php

// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('C:/wamp/www/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

// error checking
if (!@$GLOBALS['NEWSLETTER_BUILDER_PLUGIN']) { die("You must activate the newsletter plugin to see this page."); }

// load newsletter settings
$newsletterSettings = mysql_get('_nlb_settings', 1);

### on request subscription (from web form)...
if (@$_REQUEST['submitFormCustom']) {

$errorsAndAlerts = '';

// error checking
if (!@$_REQUEST['e']) { $errorsAndAlerts .= "No email address specified!<br/>\n"; }
if (!@$_REQUEST['name']) { $errorsAndAlerts .= "No name specified!<br/>\n"; }
elseif (!isValidEmail($_REQUEST['e'])) { $errorsAndAlerts .= "Invalid email specified, email must be in the format: user@example.com<br/>\n"; }

//
if (!$errorsAndAlerts) {

// convert "Display Name" <local-part@domain> to local-part@domain
$_REQUEST['e'] = array_value(isValidEmail($_REQUEST['e']), 0, 0);
$subscriber = mysql_get('_nlb_subscribers', null, array('email' => $_REQUEST['e']));

// create subscriber if they don't already exist
if (!$subscriber) {
$authkey = _nlb_generateAuthKey();
$colsToValues = array('email' => $_REQUEST['e'],
'name' => $_REQUEST['name'],
'authkey' => $authkey);
$recordNum = mysql_insert('_nlb_subscribers', $colsToValues, true);
$subscriber = mysql_get('_nlb_subscribers', $recordNum);
}

// send message & show alert
$errorsAndAlerts = '';
if ($subscriber['confirmed']) {
$errorsAndAlerts = "You're already subscribed to this newsletter.<br/>\n";
}
else {
nlb_log('0', $subscriber['num'], '1');

$to = $subscriber['email'];
$newsletterSettings = mysql_get('_nlb_settings', 1);
$mailErrors = nlb_sendMessage($to, $newsletterSettings['confirm_subject'], $newsletterSettings['confirm_html'], $subscriber);
if ($mailErrors) { die("Mail Error: $mailErrors"); }

// send alert
$success = "Thanks, we've emailed you at " .htmlencode($to). ", to confirm your subscription just check your mail and click the confirmation link.<br/>\n";
$success .= "If you don't receive an email from us within a few minutes check your spam filter for messages from " .htmlencode($newsletterSettings['from_email']). "<br/>\n";
$_REQUEST = array(); // clear form
}
}
} // E

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<style type="text/css">
body { font-family: arial; }
.instructions { border: 3px solid #000; background-color: #EEE; padding: 10px; text-align: left; margin: 25px}
</style>
</head>
<body>


<!-- INSTRUCTIONS -->
<div class="instructions">
<b>Sample Subscriber Script - Instructions:</b>
<ol>
<?php ?>
<li>Newsletter subscribers will use this script to subscribe, confirm subscriptions, and unsubscribe</li>
<li>Modify the HTML and design of this page as needed, then update <a href="http://greg.com.cmsb.me/anotherDir/cmsAdmin/admin.php?menu=_nlb_settings">Manage Url</a> under Newsletter Settings.</li>
</ol>
</div>
<!-- /INSTRUCTIONS -->

<?php if (@$success): ?>
<?php ?>

<h1>Confirm Subscription</h1>
<div style="color: #C00; font-weight: bold; font-size: 14px;"><?php echo $success; ?><br/></div>


<?php ?>
<?php else: ?>
<?php ?>

<h1>Subscribe to newsletter</h1>

<?php if (@$errorsAndAlerts): ?>
<div style="color: #C00; font-weight: bold; font-size: 14px;"><?php echo $errorsAndAlerts; ?><br/></div>
<?php endif ?>

<form method="post" action="#">
<input type="hidden" name="submitFormCustom" value="1" />
Name: <input type="text" name="name" value="<?php echo htmlencode(@$_REQUEST['name']) ?>" size="50"/>
Email: <input type="text" name="e" value="<?php echo htmlencode(@$_REQUEST['e']) ?>" size="50"/>
<input type="submit" name="subscribe" value="Subscribe" /><br/>
</form>

<?php ?>
<?php endif ?>

</body>
</html>


Alternatively, you could use the code above instead, and modify it to your requirements.

The ability to add custom placeholders to the newsletter plugin is a feature that has been requested, and we are looking into the possibility of adding it to a future release.

Let me know if you have any questions.

Thanks
Greg Thomas







PHP Programmer - interactivetools.com

Re: [greg] Newsletter Plugin.

As always - works perfectly! Thanks.
Cheers,

Tim (toledoh.com.au)