Log in

View Full Version : javascript? php? simple mailing list database?



moscarda
06-01-2006, 09:23 PM
im trying to find a simple script i can embed in an html form on my website so that a user can enter their email address to receive updates/invites, and when they click submit it will write the text they input into a text file on the sever, with each entry separated by a semicolon... so that everytime i add new work to my site, i can copy/paste the most recent mailing list directly into my mail client... like so:

user@domain.com; user1@domain1.com; user2@domain2.com; etc

is this possible? anyone have a code that does this or, if not, advice on how to code this myself? much appreciated.

also, if it were possible to have the code check the database for duplicates, that would be helpful.

djr33
06-02-2006, 01:33 AM
Sure. that's quite easy.

My comments script could be used as a base for this.
That's in a couple threads floating around.

doing the list is easy.... but checking for duplicates is a bit harder. Actually.... hmm... no, I guess it isn't.


I'll write it up for you now.

djr33
06-02-2006, 02:56 AM
Include the following php code at the VERY TOP of your page:
<?php
if ($email = stripslashes($_POST['email'])) {
$filename = "emails.phplist";
$filecontents = @file_get_contents($filename);
if ($_POST['choice'] == "join") {
if (strpos($filecontents) != "") break;
if (strlen($filecontents) > 0) $comma = ", ";
$add = $comma.$email;
$emails = $filecontents.$add;
$file = @fopen($filename, "w+");
@fwrite($file, $emails);
@fclose($file);
$message = "Your email was added to the mailing list.".
"<br>Redirecting to the last page.";
}
elseif ($_POST['choice'] == "leave") {
$edited = str_replace($email,"",$filecontents);
$file = @fopen($filename, "w+");
@fwrite($file, $edited);
@fclose($file);
$message = "Your email was removed from the mailing list.".
"<br>Redirecting to the last page.";
}
}
if ($message != "") die("<html><head>".
"<meta http-equiv=\"refresh\" content=\"3;url=\">".
"</head><body>".$message."</body></html>");
?>
<!-- YOUR HTML GOES BELOW HERE -->



<!-- THEN JUST INCLUDE THE FOLLOWING SOMEWHERE IN YOUR BODY SECTION -->
<form action="" method="post">
Join our newsletter!<br>
Email: <input type="text" name="email"><br>
<select name="choice">
<option value="join">Join</option>
<option value="leave">Leave</option>
</select>mailing list.<br>
<input type="Submit" value="Go!">
</form>



Random note... after writing this, i've decided there must be a better way to write scripts than in the post window :D


Ok... gotta run. This should work, but I haven't tested it yet...
I'll check back when I get a chance.

EDIT: Fixed two errors in the code.

moscarda
06-02-2006, 02:46 PM
hey thanks, can you dumb it down even more for me though?

1. what url goes in the <form action="(url)" method="post"> tag?
2. does the script autocreate a text file called "emails.phplist" or do i need to create one? if so, how do i do that and do i store it in the same directory folder?
3. the php script is showing up on the html page, why is that? should i make the script external and link to that url in the form action??

thanks again, sorry if these are dumb questions.

moscarda
06-02-2006, 02:47 PM
oh, and

4. where do i make the url for the redirect page?

moscarda
06-02-2006, 05:18 PM
if you go to moscarda.com/php you can view source and see what im trying to do.

djr33
06-02-2006, 05:44 PM
AHHHH! just wrote a long reply.. and it didn't get saved... well... here's the short version:

1. The form action is the current page. "" should work for that, or you could use the currentpage.php in there.

I made a mistake... change the last part of the php to this:

if ($message != "") die("<html><head>".
"<meta http-equiv=\"refresh\" content=\"3;url=\">".
"</head><body>$message</body></html>");
Note that the "3" means 3 seconds. Use what you want.
IF you want 0, like to not have a message, use comments to disable that entire thing, so you can still get it back (don't delete), but it won't do that... it'll just display your original page:

/*if ($message != "") die("<html><head>".
"<meta http-equiv=\"refresh\" content=\"3;url=\">".
"</head><body>$message</body></html>");*/

4. The URL for the redirect needs to be the CURRENT page as well. I think leaving it blank would default to that, but it might send the form again (like refresh does sometimes) and would just do an endless loop of submitting, refreshing.... so.... see what happens, and add your currentpage.php url in if it seems to matter.


2. If autocreates it.
You can control filename at the top by changing that. Whatever extension is fine... just use notepad to open in the end. If you WANT to be able to view in your browser, you could even use .htm.... but that would make it easily publicly accessible, if they could find the url of the file. Not that you'd ever give that out, so it's probably ok.
It is the SAME directory. If you want another, use "directory/filename.ext".
However, it will only create the FILE if it doesn't exist... YOU must create the directory.


3. From the link you just posted, looks like it's working ok. I'll check that out now to see what's going on.

djr33
06-02-2006, 05:49 PM
Looks like your page has a syntax error... says line 27, which, by the way it is above, is this line:
"</head><body>$message</body></html>");

I *think* it is that the $message isn't working. That should display the message.. the contents of the variable.
The way around that is this:
"</head><body>".$message."</body></html>");


Try that.


AND! You have put the php in a seperate page. It won't work.

Actually... I guess it would... if you set the url of the form to that page and the url of the redirect to the index.

But.... just put the php at the top of your index page and it won't do anything UNLESS someone has submitted the form. That's why the if is there.


Your index should be:
<?php mystuff here ?>
<html>....your page stuff...<body>
your body stuff
<form myformhere></form>
the rest of your body stuff
the end of your code</html>


Note: updating the codes above to fix the "3" error and this error.

And oh yeah... you don't need the <!-- goes in body section --> comment for the form. Doesn't hurt, but not needed.

moscarda
06-03-2006, 05:08 PM
okay i made the changes you mentioned, including putting the php in the same html file... it is still spitting out the php when you view the page...definatly not working correctly: check it out at http://moscarda.com/php ... plus, the when submitted, the form calls this error:

Method Not Allowed
The requested method POST is not allowed for the URL /php/index.html.

djr33
06-03-2006, 11:15 PM
Yeah, you're using an html page, not a php page. Clearly, this won't work with php.

Just rename index.html to index.php and it'll all work. I think.


Since you just supplied the directory (/php/) I didn't see the extension of the index... or I would've caught it earlier. Sorry.



As for the post method thing, I'm not sure why it says that. Fix the php extension, and we'll see where we are. I don't understand why that would be an error... sounds like its referring to the method="post" of the form, not the php code, as the only "post" stuff in there is variables.. not "methods". If it is related to having that in the form, but I don't really get it. html is interpreted by the browser, so your host couldn't be weird or anything... and your page isn't complex; nothing would be making that have anything in particular that would be an error.

tomyknoker
06-05-2006, 12:10 AM
Hi There,

Ok I have tried this for myself... What do I need to edit in the code for it to send me an email... When someone subscribes? or Leaves? Here is my tester page:
http://www.curiousclothing.com/email_form_test.php

djr33
06-05-2006, 12:17 AM
You can take out my two comments in the script... if you want, that is.


Does it seem to work for you? :)


Sure... you can do that. I'm no expert with the mail function.

Here's a possible version... look for "mail" at php.net if you want something else...

mail("your@email.com", "Newsletter Nofication", "This message has been automatically generated to inform you that $email has chosen to $choice the newsletter.");
(it's mail(to, subject, message))

<?php
if ($email = stripslashes($_POST['email'])) {
$filename = "emails.phplist";
$filecontents = @file_get_contents($filename);
if ($_POST['choice'] == "join") {
if (strpos($filecontents) != "") break;
if (strlen($filecontents) > 0) $comma = ", ";
$add = $comma.$email;
$emails = $filecontents.$add;
$file = @fopen($filename, "w+");
@fwrite($file, $emails);
@fclose($file);
$message = "Your email was added to the mailing list.".
"<br>Redirecting to the last page.";
}
elseif ($_POST['choice'] == "leave") {
$edited = str_replace($email,"",$filecontents);
$file = @fopen($filename, "w+");
@fwrite($file, $edited);
@fclose($file);
$message = "Your email was removed from the mailing list.".
"<br>Redirecting to the last page.";
}
////ADD BELOW
mail("your@email.com", "Newsletter Nofication", "This message has been automatically generated to inform you that $email has chosen to $choice the newsletter.");
////ADD ABOVE
}
if ($message != "") die("<html><head>".
"<meta http-equiv=\"refresh\" content=\"3;url=\">".
"</head><body>".$message."</body></html>");
?>

I *think* that will work, but I've had problems with the function before... fairly complex in some ways. you can add more, but in this case, its just a note to you, so probably fine.

tomyknoker
06-05-2006, 12:31 AM
I tried this version but the email never actually comes to me... Also says there is a line error code... Another thing is when they click submit is it possible to take it to the original page but just remove the form field and instead say your email has been added/removed?

With the previous code... What was it actually doing? was this creating a database of emails?

djr33
06-05-2006, 12:38 AM
they are the same... the email is now added to the code above, but it's the same code.
it saves the emails to a text file, emails.phplist (don't be confused by the file extension... they don't mean anything... it's a text file).


well.... the redirect accomplishes that. If you remove the option to change, then you're not letting them leave the list, or join back up if they left.


Hmm... I suppose it's not that complex.



<?php
if ($email = stripslashes($_POST['email'])) {
$filename = "emails.phplist";
$filecontents = @file_get_contents($filename);
if ($_POST['choice'] == "join") {
if (strpos($filecontents) != "") break;
if (strlen($filecontents) > 0) $comma = ", ";
$add = $comma.$email;
$emails = $filecontents.$add;
$file = @fopen($filename, "w+");
@fwrite($file, $emails);
@fclose($file);
$message = "Your email was added to the mailing list.".
"<br>Redirecting to the last page.";
}
elseif ($_POST['choice'] == "leave") {
$edited = str_replace($email,"",$filecontents);
$file = @fopen($filename, "w+");
@fwrite($file, $edited);
@fclose($file);
$message = "Your email was removed from the mailing list.".
"<br>Redirecting to the last page.";
}
mail("your@email.com", "Newsletter Nofication", "This message has been automatically generated to inform you that $email has chosen to $choice the newsletter.");
}
?>
//YOUR HTML HERE
<?php if ($message != "") { echo $message; }
else { ?>
<form action="" method="post">
Join our newsletter!<br>
Email: <input type="text" name="email"><br>
<select name="choice">
<option value="join">Join</option>
<option value="leave">Leave</option>
</select>mailing list.<br>
<input type="Submit" value="Go!">
</form><?php } ?>
//THE REST OF YOUR HTML HERE

I think that should work.


Dunno about the mail thing. some servers vary. Let's see if anyone else knows... I've never really understood the ins and outs of that function.

tomyknoker
06-05-2006, 01:06 AM
It sent me the email but just stayed on the redirect page with this
Warning: Wrong parameter count for strpos() in /home/virtual/site750/fst/var/www/html/email_form_test.php on line 6
Your email was added to the mailing list.
Redirecting to the last page.

Should I just have 2 pages one saying "your now on the subscribtion list" and the other saying "you have been removed from the subscription list"... And then it loads either one depending?

Also the email comes from Apache, any way to make it come from the person who emailed it? Or is that impossible?

tomyknoker
06-05-2006, 01:07 AM
I guess similar to this: http://www.php-scripts.com/

tomyknoker
06-05-2006, 01:09 AM
Actually any ideas hwo this one works?

http://www.akina.com.au/joinus.php

http://www.akina.com.au/joinus_thankyou.php

djr33
06-05-2006, 02:04 AM
hmmm... if you put an @ symbol before a function, it will suppress warnings...
if (@strpos($filecontents) != "") break;
if (@strlen($filecontents) > 0) $comma = ", ";

However, I think I didn't do that correctly...
yeah... here... sorry:
if (strpos($filecontents, $email) != "") break;
if (strlen($filecontents, $email) > 0) $comma = ", ";




The example you posted... it just goes to a different page. I assumed that this was going to be placed ON a page, like www.theforce.net -- look on the right, about 3/5 of the way down.

If this is JUST a page with the form on it, like one you'd get to by clicking a a link to "join the newsletter"... seems like extra work, I'd say put it on the main page.
However... if you want that, then make the action of the form be the second page, and have the php at the top of that second page. That would work fine.
that's what the example you posted does.


Yeah... the php-scripts site... same as mine... its embedded on the page. that makes more sense to me. And, the way I have it setup, it'll just submit, display a message, and redirect back to the main site. (or you can skip the redirect/message page, like we've been talking about).

tomyknoker
06-05-2006, 02:16 AM
I agree with you definitely better going this way... It still has issues though: http://www.curiousclothing.com/email_form_test.php... I'm also a bit confused I think it'd be better once it eventually redirects to the page if the submit and email was all gone and in its place just had thank you for submitting... I'm thinking that some people might try again, you know what I mean?

djr33
06-05-2006, 02:20 AM
You changed both lines?

True... the newest code I gave you should avoid that.

tomyknoker
06-05-2006, 02:25 AM
Ahhhh did I F&%^ it up? Where abouts?

djr33
06-05-2006, 02:34 AM
Wow, my bad.

if (strlen($filecontents) > 0) $comma = ", ";

just use that.

i'm sorry.... I changed both functions; only one needed to be changed.. giving you the error.

tomyknoker
06-05-2006, 02:47 AM
YAY! ok works!!!!

This is probably my fault but it doesn't redirect anymore: http://www.curiousclothing.com/email_form_test.php, also is there any way to add the email to be from the actual address the person types in? At the moment it just says from apache

djr33
06-05-2006, 03:17 AM
Can you please duplicate your page, and rename it .phps?
that will show the source (otherwise hidden as it's php).

I'll look later... gotta run...

tomyknoker
06-05-2006, 03:29 AM
http://www.curiousclothing.com/code_email_form_test.phps done! thanks for your help :)

djr33
06-05-2006, 05:03 AM
Ok, I understand what is going on.

the message displayed is still from when it WAS supposed to redirect.

This would make a LOT more sense if it was in a layout.

Here's the deal:

VERSION 1: with redirect:
The page includes, somewhere on it, a form.
when this form is sent with an email address,
you are sent back to the SAME page, for it to be interpreted.
when it does it's thing, it saves a message saying that it did it.
then it MAKES the page BLANK except for the simple message and a redirect.
That redirect then sends it back to your "main page", though it IS the same file.

VERSION 2: no redirect:
Same as above.
the form, then the form is sent:
it saves a message
however, this time, it displays the message ON THE PAGE,
where the form would have been.


It is working perfectly right now.

Find and change the message lines to these:
$message = "Your email was added to the mailing list.";

$message = "Your email was removed from the mailing list.";

removing from both:
"<br>Redirecting to the last page.";


That text was just left over.

When you put this in a layout, it'll do exactly what you want... it'll replace the form with the message. Remember to put the form in a div or table, so it can't expand with the message:
<div width="150">PHP and FORM GO HERE</div>
That way, it'll fit the same space.


That make sense?

Sorry... I've made a couple mistakes here... figuring it out as we go. Seems like it's working now, though.

tomyknoker
06-05-2006, 05:14 AM
your a legend! thanks! here you go thought you'd want to see it in all it's glory: http://www.curiousclothing.com, can you make the email come from the email address the person has entered? Or does it have to come from Apache?

djr33
06-05-2006, 05:22 AM
Pretty cool. you should add php around that alert.

Change your body tag to this:

<body<?php if ($messages == "") { ?> onLoad="MM_popupMsg('Curious? You should be. Sydney&rsquo;s rebel Ronins of streetwear are dropping their Kimono&rsquo;s and picking up gear sharper than any katana from the label that killed the cats you used to love.\r\rLike an army of modern day Mifune, the Samurai of the street blend into their surroundings, snuffing the less than worthy with killer prints and cuts this season.\r\rSleek, clean killers the Curious clothing range Ronin and Geisha are decked out in tees and singlets that reflect the nature of our fine city &ndash; crucifixes in a sombre, demure black print or laughing in the pews with glitzy, ironic silver or gold foil. The hurricane-fence print reminds you of which side of the tracks you hail from&hellip; Skulls bump heads with the clouds in a range that comes from the street, but stretches to the sky. Fashion victims? Maybe&hellip;.\r\rstockists?? + 61 415 397 606');"<?php }?>>

That way, it'll only pop up the first load, not after you submit your email.


You also changed this: $filename = "emails.phplist";
...I think.
if I try to view that, it doesn't appear to exist.

I was just gonna check how it's saving them, then see how it works to remove them.

What's the new filename? (PM to me if you want to keep it hidden, though I don't think anyone will really care here)

djr33
06-05-2006, 05:28 AM
By the way, that page is REALLY hard on the eyes. Depending on your audience, maybe, I'd definitely tone it down. Looks like it might just appeal to friends, so that's probably ok.

tomyknoker
06-05-2006, 05:33 AM
nice idea about only popping up once, but it still pops up, heres the code:http://www.curiousclothing.com/index_code.phps, also yea for some reason it doesn't create that file list... do I need to make the file first?

djr33
06-05-2006, 06:11 AM
You can try making the file. It should make it itself if you didn't.
Did you change the filename?
If you changed the directory, you MUSt create the directory first, but not the file.
See if making it changes anything... if not... I'll think about it.

Hmm... that code should work... my syntax might be off.


Wow... something is off with that .phps file. Can you make it .txt instead? I think its trying to display as a webpage, not show the source.
Actually... hitting view source shows the php too... so... whatever, that works.

One idea... find this at the end of that alert code:
<?php }?>>
and change to:
<?php } ?>>
or
<?php } ?> >

See if that helps... might just be a spaces thing.


And... yeah, you can make it from the address.


But... don't you just want it to be from the apache thing? Doesn't matter.... the file will hold the emails.... the apache thing will make it clear its auto-generated.

Change the mail command to:
mail("tom@curiousclothing.com", "Newsletter Nofication", "This message has been automatically generated to inform you that $email has chosen to $choice the newsletter.", "From: $email\r\nReply-To: $email\r\nX-Mailer: PHP/".phpversion());

That'll set the from to the email, the reply-to address to the email and the mail sender thing to php+version. (the last just being recommended by a tutorial I saw)

tomyknoker
06-05-2006, 06:25 AM
great that now works! still no luck with the alert though: http://www.curiousclothing.com/index.txt, also do you think i should have some kind of javascript so people actually have to type a legit email with the @ symbol? Have you seen this done?

djr33
06-05-2006, 06:49 AM
And the file still isn't showing up... great.
Try switching it to "emails.txt", maybe.

Yeah... I've got a script like that... did it for another page I wrote.


$at = strpos($email, "@");
$dot = strpos($email, ".", $at+2);
$atnum = substr_count($email, "@");
if ($at == false or $dot == false or $dot == strlen($email) or $atnum > 1)
{ $bad email = "The email address you entered is not valid. Please go back and try again.<br>"; }

You can put that after if ($email = stripslashes($_POST['email'])) {


Then replace "<?php if ($message != "") { echo $message; }" with:
<?php echo $bademail;
if ($message != "") { echo $message; }

**I'm not sure this is the best way.. it'll display that above the form.
you could program it to do an alert or something too.
what do you think?



Also, fix this: $message = $message = "Your email was removed from the mailing list.";
Take out one of the $message =.



To fix the alert, I put "messages" instead of "message". Fix here:
<body<?php if ($messages == "") { ?>
Change to: <body<?php if ($message == "") { ?>
sorry 'bout that... typing too fast, I guess.

djr33
06-05-2006, 06:58 AM
Oh.... hmm...
Use this:
'cause you'll need to NOT add to the list if it's invalid. right.


<?php
if ($email = stripslashes($_POST['email'])) {
$filename = "emails.phplist";
$at = strpos($email, "@");
$dot = strpos($email, ".", $at+2);
$atnum = substr_count($email, "@");
if ($at == false or $dot == false or $dot == strlen($email) or $atnum > 1)
{ $bad email = "The email address you entered is not valid. Please go back and try again.<br>"; }
else {
$filecontents = @file_get_contents($filename);
if ($_POST['choice'] == "join") {
if (strpos($filecontents, $email) != "") break;
if (strlen($filecontents) > 0) $comma = ", ";
$add = $comma.$email;
$emails = $filecontents.$add;
$file = @fopen($filename, "w+");
@fwrite($file, $emails);
@fclose($file);
$message = "Your email was added to the mailing list.";
}
elseif ($_POST['choice'] == "leave") {
$edited = str_replace($email,"",$filecontents);
$file = @fopen($filename, "w+");
@fwrite($file, $edited);
@fclose($file);
$message = "Your email was removed from the mailing list.";
}
mail("tom@curiousclothing.com", "Newsletter Nofication", "This message has been automatically generated to inform you that $email has chosen to $choice the newsletter.", "From: $email\r\nReply-To: $email\r\nX-Mailer: PHP/".phpversion());
}
}
?>

tomyknoker
06-05-2006, 07:09 AM
has an error now something to do with line 8 I think : http://www.curiousclothing.com/index.txt, I have this Javascript which I edited for another form... But not sure if adding it is different in php
<script language="JavaScript">
<!--

function formCheck(formobj){
// Enter name of mandatory fields
var fieldRequired = Array("email");
// Enter field description to appear in the dialog box
var fieldDescription = Array("Email");
// dialog message
var alertMsg = "Please complete the following fields:\n";

var l_Msg = alertMsg.length;

for (var i = 0; i < fieldRequired.length; i++){
var obj = formobj.elements[fieldRequired[i]];
if (obj){
switch(obj.type){
case "select-one":
if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
case "select-multiple":
if (obj.selectedIndex == -1){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
case "text":
case "textarea":
if (obj.value == "" || obj.value == null){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
default:
}
if (obj.type == undefined){
var blnchecked = false;
for (var j = 0; j < obj.length; j++){
if (obj[j].checked){
blnchecked = true;
}
}
if (!blnchecked){
alertMsg += " - " + fieldDescription[i] + "\n";
}
}
}
}

if (alertMsg.length == l_Msg){
return true;
}else{
alert(alertMsg);
return false;
}
}
// -->
</script>

tomyknoker
06-05-2006, 07:14 AM
ignore that script it sux... doesn't check the @

djr33
06-05-2006, 07:20 AM
Wow, heh.

Change: $bad email =
to: $bademail =

I'm out of it today. variables in php must be only one word. hehe.


that php will verify the email. what is the js supposed to do?
sorry, JS isn't my language.

Generally, though, the php is totally separate from the js.
Just do the js like normal.
the only problem might arise if:
1. the php showed the "added" message, not the form
and
2. the javascript is supposed to do something to the form.
if this becomes an issue, a php if statement could hide the javascript if it hides the form.



EDIT: "ignore that script"... ha, ok. easier, anyway.
but the php will do that :)

tomyknoker
06-05-2006, 07:20 AM
Have a good email checking script... Although can't seem to implememt it any ideas?
function isEmail(str) {
// are regular expressions supported?
var supported = 0;
if (window.RegExp) {
var tempStr = "a";
var tempReg = new RegExp(tempStr);
if (tempReg.test(tempStr)) supported = 1;
}
if (!supported)
return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
return (!r1.test(str) && r2.test(str));
}

djr33
06-05-2006, 07:22 AM
Just use the php. It's more secure, anyway.

If that doesn't work, we can figure out what next.

tomyknoker
06-05-2006, 07:26 AM
agreed... it just takes reloads the page... but doesn't give you any text warning? also uploaded the emails.txt file but doesn't seem to write anything to it...

djr33
06-05-2006, 07:34 AM
weird.

I think the issue might be that your server has file functions disabled... :\

i'm not sure what the easiest way to check that is.

make a new page, and run this:
<?php phpinfo(); ?>
or
<?php echo phpinfo(); ?>

I can't remember if it by default displays with that command.

that will tell us if it's disabled.

That command itself might be disabled, as it might be seen as a security risk to the server. not sure.

If so, then you can't do it this way.

you could try a database... do you have one you can use?

short of that... you can just use it sending you an email and adding it manually.

Or... get a better host.


Might still be the script.. i'm not sure. i'll test it on my server and see what happens tomorrow.

tomyknoker
06-05-2006, 07:34 AM
Also that alert just does not want to behave!

djr33
06-05-2006, 07:35 AM
Is the .txt file updated? I'm looking at that, and it still says $messages, not $message. If that's the newest version, just change that, and it'll be fixed.

tomyknoker
06-05-2006, 07:41 AM
weird.

I think the issue might be that your server has file functions disabled... :\

i'm not sure what the easiest way to check that is.

make a new page, and run this:
<?php phpinfo(); ?>
or
<?php echo phpinfo(); ?>

I can't remember if it by default displays with that command.

that will tell us if it's disabled.

That command itself might be disabled, as it might be seen as a security risk to the server. not sure.

If so, then you can't do it this way.

you could try a database... do you have one you can use?

short of that... you can just use it sending you an email and adding it manually.

Or... get a better host.


Might still be the script.. i'm not sure. i'll test it on my server and see what happens tomorrow.

ok well something happened! http://www.curiousclothing.com/test.php

tomyknoker
06-05-2006, 07:48 AM
This is interesting, if the user just types in a word say "test", it resets the page and the alert happens... but nothing telling them there is an error: http://www.curiousclothing.com/index.txt

djr33
06-05-2006, 09:19 AM
Yeah. That means the email was invalid. Something's not set up to give them the error message. I'll figure it out tomorrow... tired now.

Ok.... good. The test page will help see if the file stuff is enabled.

Will check soon :)

By the way, it says that safe mode is enabled... might deny you access to the files.
I'm not sure though.

Twey
06-05-2006, 09:35 AM
I can't remember if it by default displays with that command.It does.

tomyknoker
06-05-2006, 12:55 PM
Yeah. That means the email was invalid. Something's not set up to give them the error message. I'll figure it out tomorrow... tired now.

Ok.... good. The test page will help see if the file stuff is enabled.

Will check soon :)

By the way, it says that safe mode is enabled... might deny you access to the files.
I'm not sure though.

Thanks again! :) have found a nice little JavaScript for the validation...
<form name="validation" onSubmit="return checkbae()">
Please input a valid email address:<br>
<input type="text" size=18 name="emailcheck">
<input type="submit" value="Submit">
</form>
<script language="JavaScript1.2">

var testresults
function checkemail(){
var str=document.validation.emailcheck.value
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str))
testresults=true
else{
alert("Please input a valid email address!")
testresults=false
}
return (testresults)
}
</script>

<script>
function checkbae(){
if (document.layers||document.getElementById||document.all)
return checkemail()
else
return true
}
</script>

djr33
06-05-2006, 04:43 PM
I'm confused. The php I gave you will verify that correctly, I'm sure.
It checks for the @ symbol and makes sure there is at least one period after the symbol.

While that javascript may do it too, there is no point in having it.

Using javascript for verifying something is pointless. The user can get around that if they want to, and some browsers aren't compatible with it.
If you have the php anyway, how does that help?

Or, perhaps you are using the javascript as a way to notify the user when they submit the form. I suppose this is worth it. The php will do the same, though, but after its submitted. Something was weird about the way I coded the alert if the email was wrong, but that can be fixed.

Does the file still not show up?

tomyknoker
06-05-2006, 11:46 PM
I'm confused. The php I gave you will verify that correctly, I'm sure.
It checks for the @ symbol and makes sure there is at least one period after the symbol.

While that javascript may do it too, there is no point in having it.

Using javascript for verifying something is pointless. The user can get around that if they want to, and some browsers aren't compatible with it.
If you have the php anyway, how does that help?

Or, perhaps you are using the javascript as a way to notify the user when they submit the form. I suppose this is worth it. The php will do the same, though, but after its submitted. Something was weird about the way I coded the alert if the email was wrong, but that can be fixed.

Does the file still not show up?
Yea not sure what it does... can you see where the issue is with why it resets the page? but doesn't give the error? Yea Javascript I guess was just an extra bit for users who are a bit slow on the uptake :)

I made the text file but nothing writes to it... Was it to do the PHP page we looked at? Is it worth setting it up for a database? I'm a pretty quick learner... Would I need to set mySql up on my system? It's set up on the server already...

djr33
06-05-2006, 11:48 PM
an you see where the issue is with why it resets the page? but doesn't give the error?

Yeah... I think so.

Find:
<?php if ($message != "") { echo $message; }
else { ?>
<form action="" method="post">

And make it:
<?php if ($message != "") { echo $message; }
else {
echo $bademail;
?>
<form action="" method="post">


I mentioned that before, but I think it got lost in a long post.


Also, make the email text box like this: <input type="text" name="email" [b]value="<?php echo $email; ?>">

I think that will work... it'll make it so the email will be transferred if enterred incorrectly.

tomyknoker
06-05-2006, 11:56 PM
my bad you probably did :/ ummmmm I can't see where to change that code?
<?php
if ($email = stripslashes($_POST['email'])) {
$filename = "emails.txt";
$at = strpos($email, "@");
$dot = strpos($email, ".", $at+2);
$atnum = substr_count($email, "@");
if ($at == false or $dot == false or $dot == strlen($email) or $atnum > 1)
{ $bademail = "The email address you entered is not valid. Please go back and try again."; }
else {
$filecontents = @file_get_contents($filename);
if ($_POST['choice'] == "join") {
if (strpos($filecontents, $email) != "") break;
if (strlen($filecontents) > 0) $comma = ", ";
$add = $comma.$email;
$emails = $filecontents.$add;
$file = @fopen($filename, "w+");
@fwrite($file, $emails);
@fclose($file);
$message = "Your email was added to the mailing list.";
}
elseif ($_POST['choice'] == "leave") {
$edited = str_replace($email,"",$filecontents);
$file = @fopen($filename, "w+");
@fwrite($file, $edited);
@fclose($file);
$message = "Your email was removed from the mailing list.";
}
mail("tom@curiousclothing.com", "Newsletter Nofication", "This message has been automatically generated to inform you that $email has chosen to $choice the newsletter.", "From: $email\r\nReply-To: $email\r\nX-Mailer: PHP/".phpversion());
}
}
?>

tomyknoker
06-06-2006, 12:12 AM
oops sorry found it! ok works! have a look! http://www.curiousclothing.com, but still no go getting this file to write http://www.curiousclothing.com/emails.txt, is that because of my server?

tomyknoker
06-06-2006, 01:32 AM
Also I found out that safe mode was on on my server for PHP, I emailed them and this is the reply, should I turn it off? What's the norm?
Thank you for your request to turn on PHP "Power Mode" Here are some VERY IMPORTANT things to remember about turning on Power Mode:

- PHP will run as CGI which will result in slightly slower execution. This has the same effect as if you had used the .htaccess safe_mode workaround listed in the knowlegebase.

- Permissions. 777 permissions on files or folders is not needed and will not work under Power Mode. To make files executable and writable use 755 permissions instead.

- Modifying php environment values through .htaccess files will no longer work. Alternatively you'll have to edit the file /etc/php.ini to change values like upload_max_filesize and memory_limit.

More details can be found in our Knowledge Base article: http://kb.mediatemple.net/article.asp?article=10136&p=3

Please let us know via this support request if you are ready to turn on PHP Power Mode.

djr33
06-06-2006, 04:22 AM
I think that's a good idea. what does it hurt to have it on?
Slightly less security, maybe, but no big deal... just be careful.
The slower thing... whatever... it's so fast, that's funny.

Try that....

the chmod thing is about file permissions... maybe if you could chmod the file permissions for emails.txt to 777 (full read/write/execute) that would work, but not sure how you should go about that... never really needed to myself.


by the way-- Since that email error messsage is displayed right above the form, I'd change "Please go back and try again." to "Please try again."


Also, could you update index.txt? I'd like to see the exact code you're using, and I can test it on my server.

tomyknoker
06-06-2006, 05:12 AM
Hi,

Ok have uploaded the .txt file so you can check it out... Also have organised for safeMode top be off... so hopefully it will write to the file?

djr33
06-06-2006, 05:21 AM
Indeed. We'll see about the file.

gonna test on my server now.

djr33
06-06-2006, 05:22 AM
Gah! Didn't close my markup above...
You have:
Email: <input type="text" name="email" [b]value="<?php echo $email; ?>">
Take out the [b]... I was just trying to make the "new" part bold...

Email: <input type="text" name="email" value="<?php echo $email; ?>">

tomyknoker
06-06-2006, 05:31 AM
ahhhhh thought that seemed wierd... ok check it now i've updated! also take at the look at this emails.txt :D

djr33
06-06-2006, 05:32 AM
Alright... testing on my site.

I gotta run at the moment.

But... so far, I've determined:

1. The file thing works. It's your php setup... see if turning off safe mode works.

2. I submitted my email twice, and it added twice... that code must be wrong. i'll fix in a bit.
The rest works though... adding, removing...

tomyknoker
06-07-2006, 11:36 PM
Any luck with getting the same email to reject?

djr33
06-08-2006, 12:03 AM
Does everything else work now?

Sorry.... been distracted for the last day or so.

tomyknoker
06-08-2006, 12:11 AM
yea all works perfectly! just the email thing... now i have this would it be complicated to set up a database using MySQL?

djr33
06-08-2006, 05:10 AM
Well... the whole text file thing is pointless then. It's not that hard to use mysql, but, really, for this, the text file makes more sense in some ways.

Is the txt file updated to the same point as the index page? If so, I can check out why it's not replacing.

And, if you are going to set up a database, not sure it's even worth it.

But... I'd like to fix it anyway... this is a useful script. Someone else might like it.

tomyknoker
06-08-2006, 05:20 AM
Oh definitely this script is bloody fantastic! I can't believe how much you can do with just PHP to be honest I'm amazed it's inspired me to learn PHP and MySQL! Hence why I was asking about it... Was just going to make a fake database on my site to learn how to use all this stuff...

The txt file is here: http://www.curiousclothing.com/emails.txt, and works so well... if a user leaves it actually removes there email from the text file I didn't relise that! It also is updating instantaeously!

The only little glitch is the double entry thing, I tried it and this is the code that appeared:
Fatal error: Cannot break/continue 1 level in /var/www/html/index.php on line 12

djr33
06-08-2006, 06:00 AM
Just change:
if ($_POST['choice'] == "join") {
if (strpos($filecontents, $email) != "") break; to:
if ($_POST['choice'] == "join" && strpos($filecontents, $email) == "") {

This should fix it.

tomyknoker
06-08-2006, 06:23 AM
ok that appears to work... but any chance of it saying something like, "that email is already subcribed to our newsletter"... now it just reloads the page with the email address still in the field...

djr33
06-08-2006, 06:42 AM
Ah.

Here ya go:

Replace this:
if ($_POST['choice'] == "join" && strpos($filecontents, $email) == "") {
if (strlen($filecontents) > 0) $comma = ", ";
$add = $comma.$email;
$emails = $filecontents.$add;
$file = @fopen($filename, "w+");
@fwrite($file, $emails);
@fclose($file);
$message = "Your email was added to the mailing list.";
}

With:
if ($_POST['choice'] == "join") {
if (strpos($filecontents, $email) != "") {
$email = "";
$bademail = "That email is already part of our mailing list."
}
else {
if (strlen($filecontents) > 0) $comma = ", ";
$add = $comma.$email;
$emails = $filecontents.$add;
$file = @fopen($filename, "w+");
@fwrite($file, $emails);
@fclose($file);
$message = "Your email was added to the mailing list.";
}
}

Note that you can replace
$bademail = "That email is already part of our mailing list."
with
$message = "That email is already part of our mailing list."
if you'd rather have it just display that, instead of displaying the form as well.

tomyknoker
06-08-2006, 06:48 AM
I get an error now says it's on line 15 is it something to with something being open or closed {}... not sure

djr33
06-08-2006, 06:49 AM
What's the error/can you update the index.txt file so I can see line 15?

In what I just posted, I don't see any bracket error... not sure, though...

tomyknoker
06-08-2006, 06:52 AM
got it working... it was missing an ";" after
$bademail = "That email is already part of our mailing list."... I mean i'm guessing but seems to be working yea?

djr33
06-08-2006, 06:54 AM
Ah, indeed. That would do it.

Gotta hate semi-colons :p

Good... it's all working now?

tomyknoker
06-08-2006, 06:57 AM
I just got an email that said this:


This message has been automatically generated to inform you that has chosen to join the newsletter., and it came from curiousclothing.com... any idea how that works?

djr33
06-08-2006, 07:02 AM
Yeah... that's generated by the php.

What do you mean? How it comes from your site?

Or why it didn't say who joined? :p

Not sure why it didn't say who joined... weird.


Ok... I set it to set the email to blank if it was a duplicate... to get it out of a couple loops.
Anyway, just replace the current mail() line with:

if ($email != "") mail("tom@curiousclothing.com", "Newsletter Nofication", "This message has been automatically generated to inform you that $email has chosen to $choice the newsletter.", "From: $email\r\nReply-To: $email\r\nX-Mailer: PHP/".phpversion());

tomyknoker
06-08-2006, 07:05 AM
yea it just came through wierd...

i know this is being really pedantic, but is it possible to make something come up if they press submit without typing an email address :P like "please enter your email to join our newsletter..." / "please type the email address you would like to leave the newsletter from"...

tomyknoker
06-08-2006, 07:08 AM
actually can you try something... put a space in the text field and submit it... do you get this at the top of the page
Warning: strpos(): Offset not contained in string. in /var/www/html/index.php on line 5?

djr33
06-08-2006, 07:10 AM
Note above... edited with the fixing code.


Well... it'll tell them the email was invalid... close enough :p
Actually, I guess it won't; it won't do anything if the email variable is sent as blank.

Ok... here's a fix:
[code]if ($_POST['choice'] != "" and $_POST['email'] == "") $email= "Please enter your email address to ".$_POST['choice']." the newsletter.";
Put that right after "<?php".

djr33
06-08-2006, 07:15 AM
Warning: strpos(): Offset not contained in string. in /var/www/html/index.php on line 5Ah. strpos checks for the position of a character (.) after the @... and the single character is giving it problems.


Replace
if ($email = stripslashes($_POST['email'])) {

with:
$email = stripslashes($_POST['email']);
if (strlen $email>4) {

(A valid email must have a @, ., and 3 characters, minimum... probably more... that would be a@a.a)

tomyknoker
06-08-2006, 07:23 AM
ahhh i've killed it! http://www.curiousclothing.com/index.txt!!!

djr33
06-08-2006, 07:26 AM
Oh, sorry. I'm out of it.

change
if (strlen $email>4) {
to
if (strlen($email)>4) {

Change the mail thing I posted above too :)

tomyknoker
06-08-2006, 07:46 AM
hmmm couldn't get it to work... have a look at the .txt file, i updated it for ya!

tomyknoker
06-08-2006, 08:09 AM
also the alert still pops up if the user doesn't enter anything or if there email is invalid... can we disable that too? this is going to be the ULTIMATE subscribe me form!!!! :P

Twey
06-08-2006, 11:13 AM
strpos() will never return "". It will return false if the search string was not found. However, it can also return 0 if the search string is at the very beginning, so you should check its value with
... === false

moscarda
06-08-2006, 01:35 PM
Whoa, I haven't been recieving email notification about replys to this thread, so I thought no one had replied. Now there are pages and pages of stuff!

Can we back up for a minute, I obviously missed something or you all went in a different direction.

I did what you said and changed the index extention to php, I am getting this error:

Warning: Wrong parameter count for strpos() in /home/.ambassador/moscarda/moscarda.com/php/index.php on line 6
Your email was added to the mailing list.
Redirecting to the last page.

Upon which point, it does redirect back to the last page. It never writes the text file either. Did you already solve this?

moscarda
06-08-2006, 01:55 PM
okay, i just saw the part about uploading the txt file myself, i did that, and it IS indeed writing correctly.

now i need to figure out the parts about making sure that it doesn't give you the error. and, ideally, i'd like for it to NOT redirect you to a new page. it'd be cool if there was just a html label beneath the form that displayed the success or error alerts, and upon doing so, would clear the contents of the email field.

and i also need to look over the code you all posted about verifying that an email address is valid, and making sure there are no duplicates. if you could write back in one post, explaining the steps one more time, i would appreciate it. i'm not sure if things were changed for tomyknoker's project. thank you!!

djr33
06-08-2006, 05:29 PM
Things were changed slightly to fix his page, but yours sounds fairly similar.

There is no new page.... the alert IS displayed near (actually above, easy to move) the form. The email doesn't need to be left in the form... that was just so they'd have that there if they misspelled it. Easy to take out. (Or put an if so it doesn't display if it was correct).

As for explaining all the steps... what do you mean, exactly?

I believe it's pretty much flawless checking/adding/deleting emails, except for one thing, which I've been thinking about how to write.
It removes an email if you leave the list; but if you take out an email from:
email, email, email
you'll have:
email, , email
giving you an extra annoying space.
I'll figure that out... just weird, especially considering that it might fall on the ends, which would be different than the middle to fix.

tomyknoker
06-09-2006, 01:42 AM
i did some testing, if they put nothing in the field and submit, i think they need an error... also if they put a space and a letter they don't get an error... however it doesn't submit... so i guess thats ok, what do you think?

also a few posts back you said
Change the mail thing I posted above too , wasn't sure if i did it though... can you check my txt file to see... i got confused...

djr33
06-09-2006, 05:00 AM
According to what Twey said, I suppose we should change this:
if (strpos($filecontents, $email) != "") {
to

if (strpos($filecontents, $email) != false) {

Twey, I've had weird stuff go on every time I try === (not sure if I have tried !==).... can I just use != in this case?


No, you didn't update the mail command. Check back to that post to see what to replace it with.


I'm sorry guys; Graduation is tomorrow and life is really hectic.
I'll help you figure it out, tomy, and you get started, moscarda.

However, moscarda, feel free to look at his txt file
http://www.curiousclothing.com/index.txt
and copy the code out of there to replace what you have now.

It functions a little differently, so be selective in what you choose.

I'll help you both more when I get more time. :)

tomyknoker
06-09-2006, 07:57 AM
Thanks again dj... your helps been unreal!

Ok couldn't work out what to change so updated the txt file, can you let me know what is wrong?

Good luck with the Graduation tomorrow!

Twey
06-09-2006, 11:14 AM
Twey, I've had weird stuff go on every time I try === (not sure if I have tried !==).... can I just use != in this case?No. You must use !==, because 0 will evaluate as "false" with type conversion allowed, causing your check to fail if the needle is at the beginning of the haystack.

moscarda
06-09-2006, 12:47 PM
thanks a million dj, looking at tomy's code helped a lot. thank you too, tomy.

i guess the only problem now is the remaining commas when someone leaves. although i doubt it would be a problem for most mail clients, i'm sure they'd just skip over it.

dj, you should maybe submit this script to dd? i'm sure it is something a lot of people will end up using, and you deserve your due credit. good luck with graduation man, and thanks again.

djr33
06-09-2006, 08:14 PM
Yeah, I'll submit when I'm done with it.
The remaining commas aren't that hard to get rid of.... just haven't thought of a great way to do it yet.

Any other bugs before it's done?

tomyknoker
06-10-2006, 02:42 AM
I agree dj you have to submit this it's a work of art!

Ok have been playing around with it and found some things...

If the user is stupid and types a whole heap of spaces in then the email it still gets submitted, but adds the spaces http://www.curiousclothing.com/emails.txt, I am still trying to get other thing to work... If they put just antyhing below 4 spaces and submit they don't get any error... If they put over that they do get the error... I realise no one will probably do this but I guess it's better to have it perfect...

Also eventually when the error does come up and it tells them to please add a vaild email, the alert box still pops up...

I've updated it all in the txt file...

djr33
06-10-2006, 03:55 AM
Ok. I'll try to figure that stuff out.
The alert is possible to control; don't worry.

As for the spaces thing... I think I did it in the wrong order. It should allow
ANY input, not just input over 4, then mark anything under 4 characters as an invalid email. That's easy to fix.

tomyknoker
06-10-2006, 06:48 AM
still wasn't sure which mail tag to change also... thats from 2 pages back...

djr33
06-10-2006, 07:25 AM
Change the current line with mail(.....); to:

if ($email != "") mail("tom@curiousclothing.com", "Newsletter Nofication", "This message has been automatically generated to inform you that $email has chosen to $choice the newsletter.", "From: $email\r\nReply-To: $email\r\nX-Mailer: PHP/".phpversion());

This isn't a perfect solution, though, as it will fail if the user entered spaces, like you were doing before. Use that for now.

I'll fix it when I fix the rest.

Twey
06-10-2006, 01:01 PM
trim (http://www.php.net/trim)()

tomyknoker
06-13-2006, 01:47 AM
Change the current line with mail(.....); to:

if ($email != "") mail("tom@curiousclothing.com", "Newsletter Nofication", "This message has been automatically generated to inform you that $email has chosen to $choice the newsletter.", "From: $email\r\nReply-To: $email\r\nX-Mailer: PHP/".phpversion());

This isn't a perfect solution, though, as it will fail if the user entered spaces, like you were doing before. Use that for now.

I'll fix it when I fix the rest.
Thanks dj ok have added the new code...

tomyknoker
06-13-2006, 03:34 AM
Also is it complicated to do what this page does with there subscribe text box... http://www.vantageous.com/index.html, see how it has "your@email.com" then when you click it dissappears and re-appears if you click out of it?

djr33
06-13-2006, 04:01 AM
That's javascript, I think.

<input type="text" value="your@email.com" onFocus="this.value='';" onBlur="this.value='your@email.com';">


Hehe, that works. Wow. And I don't even know JS.... just guessed. That was fun :)

djr33
06-13-2006, 06:05 AM
Ah! Sorry. That will give you errors, obviously.... you type an email in, then it'll replace it with your@email.com when you click out.

Here's the fix:

<input name="email" type="text" value="your@email.com" onFocus="if (this.value=='your@email.com') {this.value='';}" onBlur="if (this.value=='') {this.value='your@email.com';}">


Additionally, you wouldn't want people submitting your@email.com to the thing.
I'd suggest:
<form action="page.php" method="post" onSubmit="if (email.value=='your@email.com') {alert('Please enter your email.'); email.focus(); return false;}">

Note that the stuff in italics can change... use the existing values in your form.

tomyknoker
06-13-2006, 07:23 AM
wow! too good...

can i add this to my already existing page?

djr33
06-13-2006, 07:39 AM
Yes. Just add the important pieces above (everything for the input tag, and everything not in italics for the form tag) to the form you have on the page.

tomyknoker
06-13-2006, 07:44 AM
I had some PHP on the code before... Do I still need that?
<INPUT TYPE="text" NAME="email" VALUE="<?php echo $email; ?>">

tomyknoker
06-13-2006, 07:48 AM
ok all done... don't you think this thing just keeps getting better and better!? it'll go down in the forum history books... ha!

do we know how to use the trim function from twey?

tomyknoker
06-13-2006, 07:49 AM
ok all done... don't you think this thing just keeps getting better and better!? it'll go down in the forum history books... ha!

do we know how to use the trim function from twey?

djr33
06-13-2006, 07:50 AM
Actually, I'm not sure where he intended it to be used 'cause it seems like there are two places it would fit.
Either way, I can just add it to both.

Is the .txt updated?

tomyknoker
06-13-2006, 07:55 AM
yea i wasn't sure either... ok yep txt file all updated... also had a look at your code to try and work out how to disable the alert box if no proper email is entered but no luck :(

djr33
06-13-2006, 08:16 AM
Not sure if I'll fix all that tonight... sorry I'm slow.

I'm looking through some stuff, and this is totally pointless:
function MM_popupMsg(msg) { //v1.0
alert(msg);
}
That's part of your javascript. It's rediculous. No clue why that is a "function".
All it does is pass the value MM_popupMSg(THIS) to alert(HERE), which is pointless.

In your body tag, use:
<BODY<?php if ($message == "") { ?> onLoad="alert('Curious? You should be. Sydney&rsquo;s rebel Ronins of streetwear are dropping their Kimono&rsquo;s and picking up gear sharper than any katana from the label that killed the cats you used to love.\r\rLike an army of modern day Mifune, the Samurai of the street blend into their surroundings, snuffing the less than worthy with killer prints and cuts this season.\r\rSleek, clean killers the Curious clothing range Ronin and Geisha are decked out in tees and singlets that reflect the nature of our fine city &ndash; crucifixes in a sombre, demure black print or laughing in the pews with glitzy, ironic silver or gold foil. The hurricane-fence print reminds you of which side of the tracks you hail from&hellip; Skulls bump heads with the clouds in a range that comes from the street, but stretches to the sky. Fashion victims? Maybe&hellip;.\r\rstockists?? + 61 415 397 606');"<?php }?> >


Well... yeah, I think that's it for tonight.
I'll get to the rest when I get a chance. Sorry :)




EDIT: Actually, that entire javascript isn't doing anything for you. Remove it all.
<SCRIPT LANGUAGE="JavaScript" TYPE="text/JavaScript">
<!--



function MM_popupMsg(msg) { //v1.0
alert(msg);
}

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
//-->
</SCRIPT>

Twey
06-13-2006, 01:01 PM
Dreamweaver does that a lot. Its "jumpMenu" script is quite funny too -- about five lines of complex, virtually unreadable Javascript, including a couple of eval calls, to do something that can be accomplished with a single statement in an event handler.

djr33
06-14-2006, 01:21 AM
Fun. Hehe.



Ok, here's the trim stuff:
Replace $email = stripslashes($_POST['email']);
with:
$email = stripslashes(trim($_POST['email']));

And
$edited = str_replace($email,"",$filecontents);
with:
$edited = trim(str_replace($email,"",$filecontents), " ,");


Let's see how that works.

tomyknoker
06-14-2006, 08:26 AM
hi dj,

thanks for the code... don't know if it's done anything... was it going to give the user an error message if they just put a couple of spaces in? and was the alert going to not pop up? i dunno... i've updated the txt file if you wanna take a look, maybe i've stuffed it some where...

djr33
06-14-2006, 08:42 AM
All that code does is removes extra spaces from the beginning/end of the email (It would make the whole thing nothing if it's only spaces... maybe an error needs to be coded in for that.)

The other occurance of it trims down the text file once a name has been removed.
This won't be noticable unless you're really looking for it:
What will happen is this:
You remove a@b.c from:
x@x.x, a@b.c, x@x.x
It'll give you:
x@x.x, , x@x.x
I'm gonna fix that (later this post I'll give you the code), and it will just make it:
x@x.x, x@x.x
So... that's fine...
But... if you had:
x@x.x, a@b.c
then removed a@b.c, you'd get:
"x@x.x, "
with and extra comma and space at the end.
The trim function will fix that.

Anyway, to finish that up, change:
$edited = trim(str_replace($email,"",$filecontents), " ,");
to:
$edited = trim(str_replace(" ,", "", str_replace($email,"",$filecontents)), " ,");


See if that works.

Basically... clear the emails from the file, then try adding emails, then deleting those emails until you get a blank file... delete the end ones especially (first added and last added) just to be sure it all works.



Anyway... at this point... how's it all working? What's left to fix?

tomyknoker
06-15-2006, 08:43 AM
That works beautifully! Give it a try...

Yea the only thing left to do (I Think) is just stopping the alert if you get an error when entering the email address and also giving people an error message if they put white space in...

Oh also the error has stopped if say they enter just "tom" I updated the txt file for ya!

djr33
06-17-2006, 10:14 AM
Oh also the error has stopped if say they enter just "tom" I updated the txt file for ya!Um... what?


The alert shouldn't be too hard.

I'm insanely busy this weekend. Sorry. When I get more time, I'll do it.

sausages
06-17-2006, 09:32 PM
Hi guys,

I've been following your progress withe the code. I was wondeirng if you would so kind as to post the final script on here. I tired updating the change syou made but i think i'm quite a bit lost. I am very new to php, but i am trying to learn. If you could be post it, it would be a great help.

thanks

djr33
06-18-2006, 10:05 AM
If you just take a look at his source code, you can likely copy most of that. The link is somewhere in the thread.

I do plan to write it up at some point... just way too tired right now. Yet another late night. Sorry, guys. I will get to it.
Probably Monday.

tomyknoker
06-25-2006, 10:38 AM
Um... what?


The alert shouldn't be too hard.

I'm insanely busy this weekend. Sorry. When I get more time, I'll do it.
Hi Dj... Hope all is well! What I meant to say was if the user types in less than 4 characters they don't actually get an error... Try it on the site...

djr33
06-25-2006, 10:43 AM
Ah.

could just add in...
if (strlen($var) < 4) {error}

something like that.

tomyknoker
06-25-2006, 10:49 AM
Where abouts do I add it? Sorry not sure...

tomyknoker
06-25-2006, 10:50 AM
dj are you any good at MySQL? Have a question...

djr33
06-25-2006, 11:10 AM
I know a little bit, but just enough to get by myself, really... wouldn't claim to be particularly "good".

As for adding that... the .txt seems to be missing, and I think I'd need to look at the whole thing.

All you really need to do is find an if that gives an error, if the email is invalid, then add in "|| $email<4" where the || means or.
Show me the .txt and I can find the right spot.

tomyknoker
06-25-2006, 11:13 AM
ok .txt file is all updated :)

djr33
06-25-2006, 11:17 AM
Ah, my error there. I was trying to make it not give errors if it was under 4 characters when it looked for the @ and such, but this will fix both:

Change this:
if (strlen($email)>4) {
$filename = "emails.txt";
$at = strpos($email, "@");
$dot = strpos($email, ".", $at+2);
$atnum = substr_count($email, "@");To:
if (strlen($email)>0) {
$filename = "emails.txt";
if (strlen($email)>4) {
$at = strpos($email, "@");
$dot = strpos($email, ".", $at+2);
$atnum = substr_count($email, "@");
}


Oh, also, add to this line:

if (strlen($email)<5 or $at == false or $dot == false or $dot == strlen($email) or $atnum > 1)

tomyknoker
06-25-2006, 11:27 AM
Ah, my error there. I was trying to make it not give errors if it was under 4 characters when it looked for the @ and such, but this will fix both:

Change this:
if (strlen($email)>4) {
$filename = "emails.txt";
$at = strpos($email, "@");
$dot = strpos($email, ".", $at+2);
$atnum = substr_count($email, "@");To:
if (strlen($email)>0) {
$filename = "emails.txt";
if (strlen($email)>4) {
$at = strpos($email, "@");
$dot = strpos($email, ".", $at+2);
$atnum = substr_count($email, "@");
}


Oh, also, add to this line:

if (strlen($email)<5 or $at == false or $dot == false or $dot == strlen($email) or $atnum > 1)Beautiful! Thanks dj excellent again! Now all I need is just to stop the alert from popping up, but whenever you get time, I know your busy! Thanks again!

tomyknoker
06-25-2006, 11:30 AM
actually could you check the .txt file? i only noticed the last line after i updated it... did i add it all in the write spot?

djr33
06-25-2006, 10:09 PM
No.
if (strlen($email)<5 or $at == false or $dot == false or $dot == strlen($email) or $atnum > 1)
if ($at == false or $dot == false or $dot == strlen($email) or $atnum > 1)
ADD the part in bold above to the EXISTING if statement.

So... just replace those two lines above with:

if (strlen($email)<5 or $at == false or $dot == false or $dot == strlen($email) or $atnum > 1)

Instead of adding the part in bold, you just added the whole thing again.... shouldn't hurt too much, but you would need an extra close bracket at the end, and it's really not doing you any good to check the same thing twice :p

tomyknoker
06-26-2006, 08:09 AM
ha ok all done! (i think :rolleyes: )

djr33
06-26-2006, 09:45 AM
Ok... here's your body tag, right?
<BODY<?php if ($message == "") { ?> onLoad="alert('Curious? You should be. Sydney&rsquo;s rebel Ronins of streetwear are dropping their Kimono&rsquo;s and picking up gear sharper than any katana from the label that killed the cats you used to love.\r\rLike an army of modern day Mifune, the Samurai of the street blend into their surroundings, snuffing the less than worthy with killer prints and cuts this season.\r\rSleek, clean killers the Curious clothing range Ronin and Geisha are decked out in tees and singlets that reflect the nature of our fine city &ndash; crucifixes in a sombre, demure black print or laughing in the pews with glitzy, ironic silver or gold foil. The hurricane-fence print reminds you of which side of the tracks you hail from&hellip; Skulls bump heads with the clouds in a range that comes from the street, but stretches to the sky. Fashion victims? Maybe&hellip;.\r\rstockists?? + 61 415 397 606');"<?php }?> >
Replace that with:
<BODY<?php if ($noalert != 1) { ?> onLoad="alert('Curious? You should be. Sydney&rsquo;s rebel Ronins of streetwear are dropping their Kimono&rsquo;s and picking up gear sharper than any katana from the label that killed the cats you used to love.\r\rLike an army of modern day Mifune, the Samurai of the street blend into their surroundings, snuffing the less than worthy with killer prints and cuts this season.\r\rSleek, clean killers the Curious clothing range Ronin and Geisha are decked out in tees and singlets that reflect the nature of our fine city &ndash; crucifixes in a sombre, demure black print or laughing in the pews with glitzy, ironic silver or gold foil. The hurricane-fence print reminds you of which side of the tracks you hail from&hellip; Skulls bump heads with the clouds in a range that comes from the street, but stretches to the sky. Fashion victims? Maybe&hellip;.\r\rstockists?? + 61 415 397 606');"<?php }?> >



And, add this right below the end of the upper php tag:
if ($message != "") $noalert=1;


Finally, right below this:
if (strlen($email)>0) {Add:
$noalert=1;


That should fix the alert problem.


Note that all you need to do is put "$noalert=1;" wherever (like in an if statement) if you don't want the alert to pop up. What I did should work, though.

Try it out... :)

tomyknoker
06-26-2006, 11:08 AM
hey dj awsome! where does this go sorry?
if ($message != "") $noalert=1;

djr33
06-26-2006, 11:25 AM
Nevermind... it's redundant... the other if will handle that.

tomyknoker
06-26-2006, 11:30 AM
ok all done! do you want to take on elast look at the .txt file? just to make sure! i've uploaded it! thanks again dj!

djr33
06-26-2006, 11:34 AM
Well.... the way to check it out is by testing... see if anything goes wrong; if not, I'll grab the txt, fix it up a bit so it's not specific to your site, and submit.

tomyknoker
10-26-2006, 12:11 PM
Well.... the way to check it out is by testing... see if anything goes wrong; if not, I'll grab the txt, fix it up a bit so it's not specific to your site, and submit.Hi dj... Is it possible to set up an emailable form using php? Similar to this but with more fields?

djr33
10-26-2006, 10:32 PM
Sure.

mail($to,$subj,$body,$headers);

Headers are complex. (They are things like from, reply-to, mailer, encoding, etc. They're not hard, but just a lot to know. Easy to look up, though, for the most part.)
The rest is easy.
Just set the vars to right values.

tomyknoker
10-26-2006, 11:15 PM
Sure.

mail($to,$subj,$body,$headers);

Headers are complex. (They are things like from, reply-to, mailer, encoding, etc. They're not hard, but just a lot to know. Easy to look up, though, for the most part.)
The rest is easy.
Just set the vars to right values.Hey dj... Any chance you could help me set up this form? I have been trying but to no avail... argh! :confused:

tomyknoker
03-13-2007, 06:46 PM
Sure.

mail($to,$subj,$body,$headers);

Headers are complex. (They are things like from, reply-to, mailer, encoding, etc. They're not hard, but just a lot to know. Easy to look up, though, for the most part.)
The rest is easy.
Just set the vars to right values.Hey dj, hope all is well... I have a similar form I need to do, and wanted your expertice! You are the coding guru after all... Let me know when you're not busy and I'll explain the details...