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 :)

connemara 03-07-2006 04:24 PM

Static Page for Newsletter subscribe-unsubscribe
 
Thank you for that suggestion. I can normally figure out a way to do the open window via javascript, just didn't know what/how to pull the results into it, so that was helpful!! Designer here, and not a programmer, so those code things will always challenge me.

I just installed and 'somewhat' customized my first xcart, and love the functionality it can have. Adding the cart to an existing site (a redo for SEO purposes) had it's own set of challenges- hence needing that open window thing for the newsletter signup off the cart.
And nice to see a "neighbour" on the list, too!
Connie Manning

xcart 4.17/specialoffers mod
:D

ShishaPipeUK 03-12-2006 08:42 AM

I modified the shopcart/skin1/news.tpl to this version below:

Code:

<TABLE>
<FORM action="{$xcart_web_dir}/mail/subscribe.php" name="subscribeform">
<INPUT type="hidden" name="redirect" value="{$redirect}">
<TR>
{if $usertype eq "C"}
<TD class="VertMenuItems">To subscribe to the newsletter, enter your email address and click "Subscribe".

{$lng.lbl_your_email}
<FONT style="FONT-SIZE: 3px;">
</FONT><INPUT type="text" name="newsemail" size="16">
<FONT style="FONT-SIZE: 5px;">
</FONT><FONT class="FormButton">{$lng.lbl_subscribe}</FONT> <INPUT type="image" {include file="buttons/go_image.tpl" full_url='Y'}>
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.


</TD>
{else}
<TD>
{$lng.lbl_your_email}


<INPUT type="text" name="newsemail" size="16">


{include file="buttons/subscribe_menu.tpl"}
</TD>
{/if}
</TD>
</TR>
</FORM>

<FORM action="{$xcart_web_dir}/mail/unsubscribe.php" name="unsubscribeform">
<INPUT type="hidden" name="redirect" value="{$redirect}">
<TR>
{if $usertype eq "C"}
<TD class="VertMenuItems">To be removed from our newsletter subscription, type in your email address and then click "Unsubscribe".

  {$lng.lbl_your_email}
<FONT style="FONT-SIZE: 3px;">
</FONT><INPUT type="text" name="email" size="16">
<FONT style="FONT-SIZE: 5px;">

  </FONT><FONT class="FormButton">{$lng.lbl_unsubscribe}</FONT> <A href="javascript:document.unsubscribeform.submit()" class="VertMenuItems">
  <INPUT type="image" {include file="buttons/go_image.tpl" full_url='Y'}></A></TD>
{else}
<TD>
{$lng.lbl_your_email}


<INPUT type="text" name="newsemail" size="16">


{include file="buttons/unsubscribe_menu.tpl"}
</TD>
{/if}
</TD>
</TR>
</FORM>
</TABLE>


ShishaPipeUK 03-12-2006 10:53 AM

Just to let you know that if this is on the main page to the left, no one can register as a new user !!!!!!!

You have to delete the unsubscribed section as the field it uses "email" is used for the register of an account.

So here is the version with unsubscribed deleted.

Code:

<TABLE>
<FORM action="{$xcart_web_dir}/mail/subscribe.php" name="subscribeform">
<INPUT type="hidden" name="redirect" value="{$redirect}">
<TR>
{if $usertype eq "C"}
<TD class="VertMenuItems">To subscribe to the newsletter, enter your email address and click "Subscribe".

{$lng.lbl_your_email}
<FONT style="FONT-SIZE: 3px;">
</FONT><INPUT type="text" name="newsemail" size="16">
<FONT style="FONT-SIZE: 5px;">
</FONT><FONT class="FormButton">{$lng.lbl_subscribe}</FONT> <INPUT type="image" {include file="buttons/go_image.tpl" full_url='Y'}>
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.


</TD>
{else}
<TD>
{$lng.lbl_your_email}


<INPUT type="text" name="newsemail" size="16">


{include file="buttons/subscribe_menu.tpl"}
</TD>
{/if}
</TD>
</TR>
</FORM>

</TABLE>


balinor 03-06-2007 04:42 AM

Re: Static Page for newsletter subscription or unsubscription
 
In case anyone is having trouble with the above code, here is an unsubscribe static page that works for 4.0.18:

Code:

<form action="mail/unsubscribe.php" method="post" name="unsubscribeform">
<table><tr><td><input type="text" name="email" size="40"></td><td>{include file="buttons/button.tpl" type="input" style="button" button_title="unsubscribe" href="javascript:document.unsubscribeform.submit()"}</td></tr></table>
<input type=hidden name=redirect value="{$redirect}">
</form>


n00bert 04-21-2007 07:55 PM

Re: Static Page for newsletter subscription or unsubscription
 
Hi,

I could be being dim, but in x-cart gold 4.1.6 there is no subscribe.php in /mail. I have only index.php and unsubscribe.php in /mail.

Since subscribe.php is being referenced from news.tpl, I cannot get this to work. I thought I might not have uploaded subscribe.php when I installed, so I checked my original 4.1.6 distribution. No subscribe.php in there either.

Does any one have any ideas as to where my subscribe.php file is?

thank you for your time and your help,

n00bert

dub713 06-22-2007 03:24 AM

Re: Static Page for newsletter subscription or unsubscription
 
any more progress on this?

i'd love to just use a simple subscribe/unsubscribe instead of the whole new thing. i didn't find subscribe.php, but in modules, subscriptions, is subscription.php not sure if its of any help.

if anyone managed to get this working, post some final code for 1.6 and above.

thanks,

DataViking 06-30-2007 06:48 AM

Re: Static Page for newsletter subscription or unsubscription
 
i'm also looking tosee how I can have a static subscription newsletter page in 4.1.7

balinor 06-30-2007 06:51 AM

Re: Static Page for newsletter subscription or unsubscription
 
We use this successfully on static pages:

http://bcsengineering.com/store/customer/product.php?productid=139&cat=0&page=1

2coolbaby 10-31-2007 09:30 AM

Re: Static Page for newsletter subscription or unsubscription
 
I am like everyone else. 4.1.x has NO subscribe.php. This prevents being able to use this code, which I have on EVERY page of my website. I wonder if I could upload my 4.0.19 subscribe.php file there??? I will try it and let you know what happened.

connemara 01-19-2008 09:46 AM

Re: Static Page for newsletter subscription or unsubscription
 
Did you find a solution to this?
I had such a nice subscribe form on static popup page from outside the cart on 4.0.8 version and with updated 4.1.9 can't seem to create proper static page from within the cart. Would love to know if adding the subscribe.php helped.
Connie

connemara 02-27-2008 04:28 PM

Re: Static Page for newsletter subscription or unsubscription
 
OK Got somewhat of a solution, not completely resolved. I wanted to use an image to link and not use the standard subscribe box.

I created static page in the root, using the code from news.php because I also wanted to use the captcha part. Styled to match site. nice.(and thanks to others on this list whose suggestions led to that result).
The image in the head template links to that static page, and opens up into a sized window using greybox technique so the customer can subscribe.

When you subscribe, it goes to the thank you page within the cart.

What I need is to (
(1) either pull that thank you into a different page that doesn't have the menu etc
OR (2) a script to open to full page. Right now, the regular thank you page opens in that defined window (about 350 X 500) so it is pretty awful. Any recommendations please? VERSION 4.1.9

Connie

robertswww 04-30-2008 12:45 PM

Re: Static Page for newsletter subscription or unsubscription
 
Quote:

Originally Posted by 2coolbaby
I am like everyone else. 4.1.x has NO subscribe.php. This prevents being able to use this code, which I have on EVERY page of my website.

This is an easy fix...

just change the ../mail/subscribe.php line to news.php as follows:
(note: modified file path from original posts #3 & #eight)

Code:

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

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


Tested and works fine in Static Pages in 4.1.9

Robert


All times are GMT -8. The time now is 01:12 PM.

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