PDA

For continued disscussion on this topic : E-mail Confirmation



George W. Bush
04-23-2001, 08:54 PM
Oh my, so many questions... you people might think I am a beginner... yes, I am... quite new to this stuff...

Ouch...

Here is background info on what works in my little experimentation...

1) I have a form, once the form is submitted the information is send to a database (mySQL).

2) The name of the person (from the submitted form) is automatically written to a page.

In the form there is also an email field where the user puts his/her email.


What I would like to do...

I do not want the form to be automatically written to a page. But I would like to send a form confirmation to the user's email, and in that email (which the user will receive) to have a link that will activate "something" that will then write to the page.

Just another method of preventing fake form submittals...

Again, I would appreciate any of your input, suggestions or directions in finding some way to do somthing like this!

Thanks again...

jonsteele
04-23-2001, 11:25 PM
Hi,

My suggestion:

Add a field to you MySQL table, called 'status' with a default value of 'Not-Active'. Then send a mail to the person using



mail($recipient,$subject,$mail_text);


on your form submit page.

In that mail have a url like http://www.yourdomain.com/index.php?activate=4 (where '4' is the users id in your table). Then have something like:



if ($activate){
mysql_connect("", "") or die ("Unable to connect to server.");
mysql_select_db("db") or die ("Unable to select database.");
$sql="UPDATE mytable SET status='Activated' WHERE id = $activate";
$result = mysql_query($sql) or die ("Unable to Activate account.");

echo "Account activated."
}
REST OF REGULAR PAGE GOES HERE.


:) Jon.

George W. Bush
04-24-2001, 05:09 AM
Hi js...

I will look into it with more detail in a couple of days.

So, the first code should be incorporated into the form? (ie. when you click on submit the form data goes into mySQL and at the same time an e-mail is sent to the person?

Where does the second code you wrote belong to?

Since I do not want the form content to be automatically sent and stored in mySQL and not written to a page from mySQL... will this kind of method allow one to send an email to the person (who in the form has indicated an email address) and only by clicking a link in that email allow the form to be written to a page?

The form data, after being submitted will be stored in mySQL, but it will not be written to a page until the person who has completed it checks a link in the email they just received?

Sorry for blabbing for so long...

I am have a funny feeling that the solution is complicated and perhaps ask tough questions...

:\

jonsteele
04-24-2001, 05:45 AM
Yeah, I think my suggestion would work.

What it does is:

Once the form is filled and submitted, the user's data is entered into the table but has the field 'status' set to 'Not-Active'. Also, the first code I gave (mail()) will send the user a mail you specify.

When the user reads the mail and clicks on the link, the second code is executed (which can be put on any page, even your main page. there will just be an "account activated" message somewhere with the rest of the page remaining the same). This second code will set the 'status' field in your table to 'Activated'. Then whenever you want to use the info in the table (maybe for another application) you will check the status field and only perform the mysql query if the field is set to 'Activated'.

Jon.

George W. Bush
05-01-2001, 06:37 PM
Still have not looked at it yet... soon... soon...

George W. Bush
05-09-2001, 08:56 PM
JS... the things that bothers me is the fact that I am not too sure how the

active=4

line will work.

Once the submittal goes into mySQL it receives a number (an ID). So if using

active=$ID

when sending that form (with an activation link), will that work then?

I am guessing so. Do you know of places of email scripts that do a similar thing as we have discussed here?

jonsteele
05-09-2001, 11:16 PM
The "activate=4" in the URL will set a variable on the page called "$activate" with the value "4".

So you'd send an email with http://www.yourdomain.com/index.php?activate=$ID.

When, they click on the link, you can use the $activate variable and activate their account.

George W. Bush
05-14-2001, 04:34 AM
Well, I am still confused as to where the if($active) would be required to be placed on the php page containing the form.

Here is the way the form page looks like:

<HTML>
<HEAD></HEAD>

<BODY>

<?php

if($submit)
{ check the form

else
{ open database, insert values
mail($recipient,$subject, $mail_text)
}
}
<FORM>...</FORM>

?>

</BODY>
</HTML>

As you notice, the form is checked, then if everything is fine a dB is opened and information is sent in. As the information is sent into mySQL dB it is given an ID. An email is then sent.

Do I send the link in the $mail_text variable? In the email I assume that "activate=$ID" will contain the same ID the form data was inputed in (in mySQL).

Now, I am not sure where if($submit) statements goes. I am thinking that is should be somewhere within the "else" statement because we want to have the database opened.

I am not sure where it goes though.

:\


[Edited by George W. Bush on 05-14-2001 at 09:19 PM]

George W. Bush
05-15-2001, 01:36 PM
I would greatly appreciate any assistance with this. Thanks.

George W. Bush
05-15-2001, 09:22 PM
It works, but one would have to remember to put the if($activate) into a new .php page for it to work, so it is separate from the form page.

But it should work.

People, read it and take notice in case you need to use it in future.

Great thanks to JS...

rick
05-18-2001, 09:04 PM
on your php page, you would need a line like this:

if($activate != "") { ... activate the form for ID $activate ... }

Since the link contained in the email will automatically popular $activate with a value, your code can then work with that ID. doess this make any sense?

jonsteele
05-19-2001, 09:09 PM
You should have

if ($activate){...
//checks if '?activate=XX' is in the URL

not

if ($activate != ""){...
//checks if variable $activate isn't blank, will give an error

The second one will give an error like (variable $activate doesn't exist if someone does not have ?activate=XX in the url.

Jon.