Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Static Page for newsletter subscription or unsubscription

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 04-06-2004, 10:02 AM
  Jon's Avatar 
Jon Jon is offline
 

X-Guru
  
Join Date: Oct 2002
Location: Vancouver, Canada
Posts: 4,200
 

Default 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>
Reply With Quote
  #2  
Old 04-06-2004, 10:07 AM
  Jon's Avatar 
Jon Jon is offline
 

X-Guru
  
Join Date: Oct 2002
Location: Vancouver, Canada
Posts: 4,200
 

Default

If anybody uses this, please let me know
Reply With Quote
  #3  
Old 04-07-2004, 09:06 AM
  B00MER's Avatar 
B00MER B00MER is offline
 

X-Guru
  
Join Date: Sep 2002
Location: Keller, TX (Cart-Lab.com)
Posts: 3,165
 

Default

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.
__________________
Cart-Lab - 100+ Social Bookmarks for X-Cart.
Reply With Quote
  #4  
Old 08-16-2004, 03:59 PM
 
rjackson7799 rjackson7799 is offline
 

Member
  
Join Date: Jan 2004
Location: Los Angeles
Posts: 24
 

Default 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?
__________________
X-Cart 4.4.0
PHP 5.2.5
Reply With Quote
  #5  
Old 01-04-2005, 10:33 PM
  bookrenter's Avatar 
bookrenter bookrenter is offline
 

Newbie
  
Join Date: Aug 2004
Location: Sunnyvale, CA USA
Posts: 4
 

Default Thanks Jon

Sweet Code. Worked great for me. Thanks for sharing it with us. Really Appreciate it.
__________________
X-Cart Pro User
Reply With Quote
  #6  
Old 05-28-2005, 07:17 PM
 
Jazzer Jazzer is offline
 

Advanced Member
  
Join Date: Mar 2005
Posts: 48
 

Default

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

Anyone know why?
__________________
Jazzer
CloserToTheDream.com

X-Cart 4.0.12
Reply With Quote
  #7  
Old 01-03-2006, 09:06 PM
  thundernugs's Avatar 
thundernugs thundernugs is offline
 

Senior Member
  
Join Date: May 2003
Location: Bend, OR
Posts: 117
 

Default

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
__________________
X-Cart Gold 4.0.17 & 4.0.18
Linux Server
Hands-On Hosting
http://www.CoreCases.com - Ipod Cases
http://www.InnovativeOutlet.com - Pet Plants and other cool stuff you need
Reply With Quote
  #8  
Old 01-09-2006, 08:42 PM
  thundernugs's Avatar 
thundernugs thundernugs is offline
 

Senior Member
  
Join Date: May 2003
Location: Bend, OR
Posts: 117
 

Default

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
__________________
X-Cart Gold 4.0.17 & 4.0.18
Linux Server
Hands-On Hosting
http://www.CoreCases.com - Ipod Cases
http://www.InnovativeOutlet.com - Pet Plants and other cool stuff you need
Reply With Quote
  #9  
Old 03-05-2006, 08:35 AM
  connemara's Avatar 
connemara connemara is offline
 

Senior Member
  
Join Date: Jan 2006
Location: Vancouver Island, Canada
Posts: 167
 

Default 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
__________________
Versions 4.7.6
multiple mods and customizations
Reply With Quote
  #10  
Old 03-06-2006, 10:31 AM
  Jon's Avatar 
Jon Jon is offline
 

X-Guru
  
Join Date: Oct 2002
Location: Vancouver, Canada
Posts: 4,200
 

Default

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
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 09:00 PM.

   

 
X-Cart forums © 2001-2020