Page 1 of 17

[how to] put a subscribe form on one of my website pages

PostPosted: 11:09pm, Thu 06 Jul, 2006
by crazydog
How do I, instead of using a subscribe page, just put a form on my homepage with an Email Address field and a submit button, and have that sign people up?

PostPosted: 12:28am, Fri 07 Jul, 2006
by H2B2
EDIT: It is recommended to first read this doc: Custom Subscribe Form
------

Place this code in a table cell and change it to match your setup and layout
Code: Select all
<!-- newsletter subscribe below here -->

<script language="Javascript" type="text/javascript">
var fieldstocheck = new Array();
fieldnames = new Array();
function checkform() {
for (i=0;i<fieldstocheck.length;i++) {
if (eval("document.subscribeform.elements['"+fieldstocheck[i]+"'].value") == "") {
alert("Please enter your "+fieldnames[i]);
eval("document.subscribeform.elements['"+fieldstocheck[i]+"'].focus()");
return false;
}
}
return true;
}
function addFieldToCheck(value,name) {
fieldstocheck[fieldstocheck.length] = value;
fieldnames[fieldnames.length] = name;
}
</script>

<form method="post" action="http://www.yourdomain.com/lists/?p=subscribe&id=1" name="subscribeform">
Email:<input type="text" name="email" value = ""><br>
<script language="Javascript" type="text/javascript">addFieldToCheck("email","Email Address");</script>
Name: <input type="text" name="attribute2" value = "">
<script language="Javascript" type="text/javascript">addFieldToCheck("attribute2","Name");</script>
<input type="hidden" name="list[1]" value="signup" />
<input type="submit" name="subscribe" value="Subscribe" onClick="return checkform();">
</form>

<!-- newsletter subscribe ends here -->

PostPosted: 8:53am, Sat 08 Jul, 2006
by crazydog
Alright. I changed it to fit what I need...
(Script is attached as txt file, because phpbb is editing my code =/)

(mywebsite.com isn't what I have in my code.)

All it does is brings me to http://mywebsite.com/newsletter/lists/?p=subscribe&id=1

PostPosted: 5:34am, Mon 10 Jul, 2006
by H2B2
Can't download your attachment. The download link seems to be empty. Try to post it here and be sure to check the box "Disable HTML in this post".

PostPosted: 12:58pm, Mon 10 Jul, 2006
by H2B2
OK, was able to download your code today. This is what you placed in your attachment:
Code: Select all
<script language="Javascript" type="text/javascript">
var fieldstocheck = new Array();
fieldnames = new Array();
function checkform() {
for (i=0;i<fieldstocheck.length;i++) {
if (eval("document.subscribeform.elements['"+fieldstocheck[i]+"'].value") == "") {
alert("Please enter your "+fieldnames[i]);
eval("document.subscribeform.elements['"+fieldstocheck[i]+"'].focus()");
return false;
}
}
return true;
}
function addFieldToCheck(value,name) {
fieldstocheck[fieldstocheck.length] = value;
fieldnames[fieldnames.length] = name;
}
</script>
<form method="post" action="http://mywebsite.com/newsletter/lists/?p=subscribe&id=1" name="subscribeform">
<input type="text" name="email" value = "Email Address" size="15"><br>
<script language="Javascript" type="text/javascript">addFieldToCheck("email","Email Address");</script>
<input type="hidden" name="list[1]" value="signup" />
<center><input type="submit" name="subscribe" value="Subscribe" onClick="return checkform();"></center>
</form>


And this is what you stated a being a problem:
(mywebsite.com isn't what I have in my code.)

All it does is brings me to http://mywebsite.com/newsletter/lists/?p=subscribe&id=1

But you don't mention what exactly the problem is, and I can't check for myself as the domain you entered in your code isn't yours. So please describe what the problem is: what were you expecting that didn't happen, and what happened that you didn't want to happen.

PostPosted: 1:04pm, Mon 10 Jul, 2006
by crazydog
All that does is bring me to the default subscribe page.
I want the form to automatically submit it, not having to use the premade subscribe form.

PostPosted: 1:30pm, Mon 10 Jul, 2006
by H2B2
Allright, could you check in the Admin backend what the list ID is, and post it here?

PostPosted: 1:45pm, Mon 10 Jul, 2006
by H2B2
And than try changing this part of the form code:
Code: Select all
<form method="post" action="http:/mywebsite.com/newsletter/lists/?p=subscribe&id=1" name="subscribeform">

to this:
Code: Select all
<form method="post" action="http://mywebsite.com/newsletter/lists/?p=subscribe" name="subscribeform">

and check you have this line of code:
Code: Select all
<input type="hidden" name="list[XXX]" value=signup>
where XXX is the list ID you have.


Also, check this setting on the configuration page (admin >> configure):
- if there is only one visible list, should it be hidden in the page and automatically subscribe users who sign up (0/1)
true

PostPosted: 3:51pm, Mon 10 Jul, 2006
by crazydog
That worked. thanks

Thanks

PostPosted: 7:36am, Sun 06 Aug, 2006
by Scrampy
I got it... followed instructions and got the subscribe listed on my own site (every page using template) ... very helpful, and much appreciated.

Great work H2B2

PostPosted: 5:40am, Tue 05 Sep, 2006
by thaivisitor
I must give my heartfelt gratitude to you H2B2!!!!

I have checked thru various posts to try to customize my subscription into my homepage without any success of doing it right but your instructions are just simply the best.

All I did was to copy your script(of course using my own domain and directory), paste it into the Code view of my website in MS Frontpage, edit it from Design view and I got my subscription working perfectly!!!! :lol:
It was done in 15 minutes (not counting the other hours that I took to look thru the forums).

Now I have to go about trying to figure out some other functions of phplist :cry:
viewtopic.php?t=2232&start=75

Anyway, once again, I thank you very much.

Cheers
ThaiVisitor

PostPosted: 12:11pm, Mon 18 Sep, 2006
by tomraffe
When I fill in the form on my site I get redirected to http://www.example.co.uk/lists/?p=subscribe where I get the following message

"The following required values are missing: Email Addresses you entered do not match"

Any ideas?

PostPosted: 12:27pm, Mon 18 Sep, 2006
by H2B2
tomraffe wrote:"The following required values are missing: Email Addresses you entered do not match"

Did you try disabling email confirmation in Admin >> subscribe pages >> check the radio button "Don't display email confirmation".

PostPosted: 12:40pm, Mon 18 Sep, 2006
by tomraffe
Thats corrected that bit. It now says Name, is a required field, despite me completing it on the form. Obviously there is a problem with the field and the attribute?

My code is below. The Name attribute in my DB is simply Name.

Code: Select all
<!-- newsletter subscribe below here -->

<script language="Javascript" type="text/javascript">
var fieldstocheck = new Array();
fieldnames = new Array();
function checkform() {
for (i=0;i<fieldstocheck.length;i++) {
if (eval("document.subscribeform.elements['"+fieldstocheck[i]+"'].value") == "") {
alert("Please enter your "+fieldnames[i]);
eval("document.subscribeform.elements['"+fieldstocheck[i]+"'].focus()");
return false;
}
}
return true;
}
function addFieldToCheck(value,name) {
fieldstocheck[fieldstocheck.length] = value;
fieldnames[fieldnames.length] = name;
}
</script>

<form method="post" action="http://www.e-discounts.co.uk/lists/?p=subscribe" name="subscribeform">
<input type="hidden" name="list[1]" value=signup>
Email:<input type="text" name="email" value = ""><br>
<script language="Javascript" type="text/javascript">addFieldToCheck("email","Email Address");</script>
Name: <input type="text" name="Name" value = "">
<script language="Javascript" type="text/javascript">addFieldToCheck("Name","Name");</script>
<input type="hidden" name="list[1]" value="signup" />
<input type="submit" name="subscribe" value="Subscribe" onClick="return checkform();">
</form>

<!-- newsletter subscribe ends here -->

PostPosted: 1:58pm, Mon 18 Sep, 2006
by H2B2
tomraffe wrote:It now says Name, is a required field, despite me completing it on the form. Obviously there is a problem with the field and the attribute?
Yes, that is exactly the problem. Instead of "Name" you should use something like "attributeX" for this form field, where X is the ID number of the attribute.

Assuming your attribute "Name" has ID number "1", try changing this:
Code: Select all
<input type="text" name="Name" value = "">
<script language="Javascript" type="text/javascript">addFieldToCheck("Name","Name");</script>

to this:
Code: Select all
<input type="text" name="attribute1" value = "" ><script language="JavaScript" type="text/javascript">addFieldToCheck("attribute1","Name");</script>


You can check the ID number of the attribute you created in :
- Admin >> subscribe pages >> Edit
or in:
- Admin >> Manage users >> User attributes
Find the attribute "Name" and you should see the ID number on the top left side.

BTW, your form code only need one instance of this input tag:
Code: Select all
<input type="hidden" name="list[1]" value="signup" />