Author Topic: Populate form text box from URL for email unsubscribe link  (Read 415 times)

jt lsav

  • New Member
  • *
  • Posts: 6
  • Karma: 0
    • View Profile
Populate form text box from URL for email unsubscribe link
« on: March 09, 2012, 11:52:36 AM »
We are doing a simple email campaign and need to include an unsubscribe link. I have the page and db built for the page however I'd like the 'email' field to populate from a unique url, such as:

www.myweb.com/unsubscribe.php?email=email@gmail.com

I can't seem to get this info from the url to the text box. Thanks in advance for any assistance!

ErnieAlex

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 1847
  • Karma: 32
    • View Profile
Re: Populate form text box from URL for email unsubscribe link
« Reply #1 on: March 09, 2012, 12:57:16 PM »
When text is passed into a page from an argument such as your "?email=Ernie@Alex.com",
it is posted to the page.  BUT, it is NOT a POST variable.  POST is used for FORM's posting to pages.
You need to use GET's instead.

   So, on your unsubscribe.php page, you would add code to "get" the info.  Use something like this:
PHP Code: [Select]

  $unsubscribe_email 
$_GET['email'];   //Get the email sent from the user-click...


Hope that helps...   (If not, show us some code!)

jt lsav

  • New Member
  • *
  • Posts: 6
  • Karma: 0
    • View Profile
Re: Populate form text box from URL for email unsubscribe link
« Reply #2 on: March 09, 2012, 01:02:43 PM »
Here's the working end of the code:

Code: [Select]
<script language="JavaScript" type="text/javascript">
<!--
function checkform ( form )
{
  // ** START **
  if (form.email.value == "") {
    alert( "Please enter your email address." );
    form.email.focus();
    return false ;
  }
  // ** END **
  return true ;
}
//-->
</script>


</head>

<body>

<!-- START: gradient -->
<div id="gradient">

<!-- START: main -->
<div id="main">

<?php include('inc/masthead.inc.php'); ?>

<!-- START: flash-content -->
<div id="flash-content">

</div>
<!-- END: flash-content -->

<!-- START: content-wrapper -->
<div id="content-wrapper">



<!-- START: primary-content -->
<table id="primary-content" cellspacing="0">
<tr>

</tr>

<tr>
<td id="body">
<table id="columns" cellspacing="0">
<tr>
<td>
<h2>Unsubscribe From Our Mailing List</h2>




<form action="insert.php" method="post" onsubmit="return checkform(this);">
Email: <input type="text" name="email" />
<input type="submit" value="remove" />
</form>
</ul>
</td>

</tr>
<tr><td id="gutter">&nbsp;</td></tr>
</table>
</td>
</tr>
</table>
<!-- END: primary-content -->

</div>
<!-- END: content-wrapper -->

<?php include('inc/footer.inc.php'); ?>
</div>
<!-- END: main -->

</div>
<!-- END: gradient -->

</body>

ErnieAlex

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 1847
  • Karma: 32
    • View Profile
Re: Populate form text box from URL for email unsubscribe link
« Reply #3 on: March 09, 2012, 01:16:43 PM »
I'm confused...  Normally, an unsubscribe link simply takes the email address that was sent to it, handles saving the data to the database and displays a message that says "You have been removed from our mailing list!".  You do not want the user to have to retype the email address in and submit another form.  That would just be annoying to the user.

So, fist, get rid of the Javascript stuff and the form stuff and make it just a simple PHP script.
It that script, just GET the email address (you already have that and it was inside of the unsubscribe link on the original email that the user clicked on), open your database, delete their info or if you want to keep their data for future use, just make it not-mailable so no further emails will be sent.  Lastly, echo back a small page with your company's header/footer and a simple "You have been removed, etc" message in the middle.  (No links or menu buttons needed as they don't want to be there.)

Did that make sense?  Hope so, Good luck...

jt lsav

  • New Member
  • *
  • Posts: 6
  • Karma: 0
    • View Profile
Re: Populate form text box from URL for email unsubscribe link
« Reply #4 on: March 09, 2012, 01:24:12 PM »
It does make sense however this page is used for other mailing campaigns in which the mailer does not have the ability to inject the users email address. Thus the need for a general unsubscribe page in which if the url is populated with the email it will automatically be inputted to the form and they simply click submit, or the user can manually input an email address and click submit.

ErnieAlex

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 1847
  • Karma: 32
    • View Profile
Re: Populate form text box from URL for email unsubscribe link
« Reply #5 on: March 09, 2012, 02:19:21 PM »
Well, not sure what you need then, but, this code:
Code: [Select]
               function checkform ( form )
                 {
                    // ** START **   
                    if (form.email.value == "") {
                       alert( "Please enter your email address." );
                       form.email.focus();
                       return false ;
                     }
                       // ** END **
                       return true ;
                 }
Should be more like this:
Code: [Select]
            function checkform ( form )
                     {   
                       // ** START **
                       if (form.email.value == "") {
                         alert( "Please enter your email address." );
                         form.email.focus();
                         return false ;
                       }
                     else
                       {
                       // ** END **
                       return true ;
                       }
                   }
  And, of course this will NOT post as there is no post code anywhere.  The submit button cancels the form's posting by switching it to the Javascript, so you will have to add the submitting of the form there.  It would be done with this type of JS command:     document.forms["myform"].submit();
  Of course, you need to set the ID="myform" in the <FORM> tag for this to work...

Hope that is what you were asking for...  Good luck...

jt lsav

  • New Member
  • *
  • Posts: 6
  • Karma: 0
    • View Profile
Re: Populate form text box from URL for email unsubscribe link
« Reply #6 on: March 09, 2012, 10:49:48 PM »
All of the POST data is in a separate doc, view code referencing insert.php. all db info is contained there.

jt lsav

  • New Member
  • *
  • Posts: 6
  • Karma: 0
    • View Profile
Re: Populate form text box from URL for email unsubscribe link
« Reply #7 on: March 12, 2012, 05:19:04 PM »
?Bump?

jt lsav

  • New Member
  • *
  • Posts: 6
  • Karma: 0
    • View Profile
Re: Populate form text box from URL for email unsubscribe link
« Reply #8 on: March 12, 2012, 06:56:08 PM »
Well, I finally figured it out.... This was the code snip I was missing:

Code: [Select]
Email: <input type="text" name="email" value="<?php echo $_GET['email']; ?>" />
Specifically the info after the 'value' variable.

Ernie, thanks for your help. I realize I may have not been as specific as necessary in my question.

ErnieAlex

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 1847
  • Karma: 32
    • View Profile
Re: Populate form text box from URL for email unsubscribe link
« Reply #9 on: March 12, 2012, 07:03:31 PM »
Great!  Always nice when a puzzle problem is solved!   I was gone for awhile, so never got back to your code...  Happy you solved it...    CYA in the bitstream...