X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Static Page for newsletter subscription or unsubscription (https://forum.x-cart.com/showthread.php?t=7033)

Jon 04-06-2004 10:02 AM

Static Page for newsletter subscription or unsubscription
 
Here's the standard code. It posts to itself, so the page can be stand alone with your headers and/or footers, or you can just make a small box on your index page or something. Lots of uses, so you can be creative.

If you copy all this code, modify your database settings, and rename it newsletter.php and upload it, it should work for you.

Code:

<?

#=================================#
# CODE WRITTEN BY JON PETERS      #
# PROVIDED AS IS WITH NO WARRANTY #
# I.E. USE AT YOUR OWN DESCRETION #
#=================================#

// Initialize variables

$error = "";
$response = "";


#=================================#
# CONFIG                          #
#=================================#

// Edit this with your own database information

$sql_host ="localhost";
$sql_user ="YOUR_DATABASE_USER";
$sql_db ="YOUR_DATABASE";
$sql_password ="YOUR_DATABASE_PASSWORD";

// End Config


#=================================#
# FUNCTIONS                      #
#=================================#

function check_email($str) {
        //returns 1 if valid email, 0 if not
        if(ereg("^.+@.+\\..+$", $str)) { return 1; }
        else { return 0; }
}

#=================================#
# ON POST COMMANDS                #
#=================================#

if ($_POST['mode'] != "") {

        // Connect and Select a Database
        $link = mysql_connect($sql_host, $sql_user, $sql_password) or die ("Couldn't connect to MYSQL Database");
        mysql_select_db($sql_db) or die("Could not select the database '" . $sql_db . "'.  Are you sure it exists?");

        // Format the email address
        $email = $_POST['email'];
        $email = strip_tags($email);
        $email = addslashes($email);

        // Check for valid email address
        if (check_email($email) != 1) { $error = Y; }
        if ($error != "") {
                $response = "ERROR: Invalid E-mail address!";
        }

        // If there is not an error, we check the mode
        // Subscribe
        elseif ($_POST['mode'] == "subscribe") {
                $result = mysql_query("select email from xcart_maillist where email='$email' LIMIT 1");
                $emailcheck = mysql_fetch_row($result);
                $emailcheck = $emailcheck[0];
                mysql_free_result($result);
                if ($emailcheck != "") { $response = "ERROR: E-mail is already subscribed to the Newsletter."; }
                else {
                        mysql_query("INSERT INTO xcart_maillist values('$email', now())");
                        $response = "ADDED: E-mail address successfully added to the Newsletter!";
                }

        }
        // Unsubscribe
        elseif ($_POST['mode'] == "unsubscribe") {
                $result = mysql_query("select email from xcart_maillist where email='$email' LIMIT 1");
                $emailcheck = mysql_fetch_row($result);
                $emailcheck = $emailcheck[0];
                mysql_free_result($result);
                if ($emailcheck == "") { $response = "ERROR: E-mail address is not subscribed to the Newsletter."; }
                else {
                        mysql_query("DELETE FROM xcart_maillist where email='$email' LIMIT 1");
                        $response = "REMOVED: E-Mail address has been successfully removed from the Newsletter.";
                }
        }
}

?>

<html>

<head>
<title>Newsletter Subscription</title>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
</head>

<? if ($response != "") { echo "<font color=\"#FF0000\">$response</font>"; } ?>

<form name="newsletter" action="newsletter.php" method="POST">

 <center>
 <table border="0" width="250" cellpadding="2">
  <tr>
  <td width="50%"><input name="email" size="15"></td>
  </tr>
  <tr>
  <td width="50%">
        <input type="radio" value="subscribe" checked name="mode"> Subscribe
       

        <input type="radio" value="unsubscribe" name="mode"> Unsubscribe
  </td>
  </tr>
  <tr>
  <td width="50%">
    <p align="center"><input type="Submit" value="Submit" name="Submit"></td>
  </tr>
 </table>
 </center>

</form>

</body>

</html>


Jon 04-06-2004 10:07 AM

If anybody uses this, please let me know :D

B00MER 04-07-2004 09:06 AM

Just thought I'd add a tpl version of this, same sense, unsubscribe and subscribe forms on one page:

Code:

To subscribe to the newsletter, enter your email address and click "Subscribe".


<form action="../mail/subscribe.php" method=get name=subscribeform2>
<input type="text" name="email" size="40">Subscribe
<input type=hidden name=redirect value="customer">
</form>

<hr size=1 width=420 align="left">

To be removed from our newsletter subscription, type in your email address and then click "Unsubscribe".


 
<form action="../mail/unsubscribe.php" method=get name=unsubscribeform>
<input type="text" name="email" size="40">Un-Subscribe
<input type=hidden name=redirect value="customer">
</form>

Subscribing to our newsletter is free and your data will not be shared or sold with any other companies.  Please see our privacy statement for details.


Kudos to Jon for sharing his code. :wink:

rjackson7799 08-16-2004 03:59 PM

Thanks for the .tpl
 
Thanks for the code Boomer. Quick question, what .tpl file do I modify to change the "thank you for subscribing" page?

bookrenter 01-04-2005 10:33 PM

Thanks Jon
 
Sweet Code. Worked great for me. Thanks for sharing it with us. Really Appreciate it.

Jazzer 05-28-2005 07:17 PM

Tried the .tpl version and I keep getting the error message "You have specidifed and incorrect e-mail address."

Anyone know why?

thundernugs 01-03-2006 09:06 PM

i get the same "You have specified an incorrect e-mail address" when trying the code in a static html and in a tpl file

anyone know how this may be?

http://www.innovativeoutlet.com/store/pages.php?pageid=2

thanks

thundernugs 01-09-2006 08:42 PM

i found the fix for the Subscribe/Unsubscribe page by Boomer:

"You have specified an Incorrect e-mail address"

in the subscribe part, change this

Code:

To subscribe to the newsletter, enter your email address and click "Subscribe".

 <form

action="/store/mail/subscribe.php" method=get name=subscribeform2> <input type="text"

name="email" size="40">Subscribe <input type=hidden

name=redirect value="customer"> </form>


to this

Code:

To subscribe to the newsletter, enter your email address and click "Subscribe".

 <form

action="/store/mail/subscribe.php" method=get name=subscribeform2> <input type="text"

name="newsemail" size="40">Subscribe <input type=hidden

name=redirect value="customer"> </form>


notice the name changed from email to newsemail

this fix worked with my version 4.0.17

connemara 03-05-2006 08:35 AM

Static Page for Newsletter subscribe-unsubscribe
 
I am using the great ideas from this post to add the subscribe onto the front page of our site, that is static, and separate from the store. That works great. BUT I would like the resulting message (your email was successfully added, or removed, etc) to open in a new window on its own without going into the cart itself. Can this be done and how? I can create the new window part, but how would I pull in the results?

Any help appreciated.

Connie Manning
added mod/ special offers

Jon 03-06-2006 10:31 AM

You can use javascript in your form submission code to have it open in a new window. Just google for the code.

Nice to see other Vancouverites here :)


All times are GMT -8. The time now is 02:09 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.