PDA

View Full Version : Passing a value to a Form ...


jmueller0823
04-15-2003, 07:01 PM
Here's what I want to do.
We want to provide an "un-subscribe" link in our mailings.

The URL in each e-mail message would be automatically created from our database and might look like this:

http://www.site.com/unsubscribe.shtml?email=remove_this_user@yahoo.com

What we'll do is pass the user's email address to the unsubscribe page.

When the user clicks on his removal link, our "unsubscribe" page would launch and his email address would be automatically pre-entered in the "email" field in the form on that page.

QUESTION: How do I get the "email" value, passed in the command line, in to the form? Must be possible using JS, right?

Thanks!

ucm
04-15-2003, 11:59 PM
For security purposes, there is no way to get their e-mail address ( without a bit of 'hacking' ), generally, without already having it on file like in MySQL or something... Like the visitor visits your site, signes up and provides their e-mail addy then your site stores it in MySql ( or something ) and then you could use it in your php ( or something ) code to allow them to unsubscribe...


The way to go about it would be to have the server-side page add their e-mail address in the e-mail before sending it to the user...

for example in php, it would something like:
NOTE: this example assumes you already have their e-mail addys on file in MySQL...

<center>
Here is the content of your e-mail to your subscribers...



<?
Access MySQL here and pull out their e-mail address, store it in variable $subscribersEmail
?>


<br><br><center>
<a href="http://www.site.com/unsubscribe.shtml?email=<?echo $subscribersEmail;?>">Click here to UNsubscribe...</a>
<br><br></center>




something along those lines should do the trick ;)

jmueller0823
04-16-2003, 09:46 AM
ucm-- thanks for your help, but you missed my point.

I already stated that the e-mail address would be acquired from our database. That's not an issue.

Also, I already know how to create the unsubscribe link from the e-mail address. That's not an issue.

Please review my original post. Maybe I wasn't clear...

Here's the scenario:

>The user clicks on the unsubscribe link in his email message.
>Our unsubscribe page launches [unsubscribe.shtml].
>The user's email address is passed to the above page from the command line.
>There is a form on this page.
>We want the user's email address to automatically populate the "email" field in the unsubscribe form.

++++++++++++++++++++++++++++++++++++++++++++++++
QUESTION: How do we extract the email address from the command line
and insert it into the "email" field in the unsubscribe form on the unsubscribe page?
++++++++++++++++++++++++++++++++++++++++++++++++

Again, the unsubscribe URL [command line] in the email message would look something like this:

http://www.site.com/unsubscribe.shtml?email=remove_this_user@yahoo.com

By the way, I am open to using php.

Thanks.

jmueller0823
04-16-2003, 04:42 PM
[bump] anyone?:rolleyes:

Jon Hanlon
04-17-2003, 12:54 AM
<script language="Javascript">
function plusUnescape(str) { // the unescape function won't convert plus signs
str = '' + str; // to spaces; like you see in search strings
while (true) {
var j = str.indexOf('+');
if (j == -1) break;
str = str.substring(0,j) + ' ' + str.substring(j+1,str.length);
}
return unescape(str);
}

function getArgument (theKey) {
var args = new Array ();
var argstring = window.location.search;
if (argstring.charAt(0) != '?') return false;
argstring = argstring.substring(1, argstring.length);
var argarray = argstring.split('&');
for (var j=0; j < argarray.length; j++) {
var singlearg = argarray[j].split('=');
if (singlearg.length != 2) continue; // not a valid argument
var argsKey = plusUnescape(singlearg[0]);
var argsValue = plusUnescape(singlearg[1]);
args [argsKey] = argsValue;
}
return args[('' + theKey)]
}

function initPage() {
var emailArg = getArgument("email")
if (!emailArg) return false;
document.forms.myForm.mail.value = emailArg
}
</script>

<body onload="initPage()">

<form name="myForm">
<input type="text" name="mail">
</form>



The location object will contain http://www.site.com/unsubscribe.shtml?email=remove_this_user@yahoo.com

The search property of the location will contain ?email=remove_this_user@yahoo.com

The code above finds remove_this_user@yahoo.com using the key email and then pops it into a form.

jmueller0823
04-17-2003, 12:59 PM
Jon, you're a genius. Thank you.

agent002
04-17-2003, 02:38 PM
...but since you seem to have access to PHP or something similiar, wouldn't it be easier and cross-browser safer to make the PHP (etc) script parse the email attribute from the query string?