Jump to content

Need to pass Email variable to a Form.


lazerbrains

Recommended Posts

Currently I have a PHP file that is pulling information from a table in the Database and inserting it into an HTML table. It consists of the fields: Last_Name, First_Name, Party, District, Address, CIty, State, Zip, and Email. And the Email field is being converted to a Hyperlink.  (All working fine so far)

 

I also have a form that has a prewritten letter to be sent to the email address. I need to have the HyperLink from the Email pass the address to the form to allow me to send it. I am not sure how to get this to happen. Here is the code I have so far:

 

The pull from the database:

<?php




$dbhost = 'localhost';
$dbuser = 'removed';
$dbpass = 'removed';
$db = 'removed';

$link = mysql_connect($dbhost, $dbuser, $dbpass)or die(mysql_error());
mysql_select_db($db)or die(mysql_error());

$result = mysql_query("SELECT * FROM 2011members") 
or die(mysql_error());  


echo "<table border='1'>";
echo "<tr> <th>Last Name</th> <th>First Name</th> <th>Party</th> <th>District</th> <th>Address</th> <th>City</th> <th>State</th> <th>Zip</th> <th>Email</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td>"; 
echo $row['Last_Name'];
echo "</td><td>"; 
echo $row['First_Name'];
echo "</td><td>"; 
echo $row['Party'];
echo "</td><td>"; 
echo $row['District'];
echo "</td><td>"; 
echo $row['Address'];
echo "</td><td>"; 
echo $row['City'];
echo "</td><td>"; 
echo $row['State'];
echo "</td><td>"; 
echo $row['Zip'];
echo "</td><td>"; 
//Normal Pull
//echo $row['Email'];
//echo "</td><td>"; 
//Just Hyperlink
//echo '<a href="http://',Email,'">',Email,'</a>';
//echo "</td></tr>"; 
echo '<a href="http://'.$row['Email'].'">'.$row['Email'].'</a>';
echo "</td></tr>"; 
} 

echo "</table>";
?>

 

The Form:

<?php 
if($_POST){
$to = 'becca@windfallstudio.com';
$subject = "WHAT SHOULD THIS BE";	
$message  =  "Date: $date\n\r".
			 "Dear $legislator,\n\r".
			 "As a constituent of yours, I urge you to closely review $bill as it pertains to the distribution and allotment of the 4 percent bed tax collected at lodging properties in Montana.\n\r".
			"Tourism is very important to Montana. Not only it is the second largest industry in Montana, it is also a key economic engine for businesses and the thousands of Montanans that have jobs because of tourism.\n\r".
			"Nearly 10 million visitors travel to our state each year, contributing between $2.4 billion and $3 billion annually into our economy. In addition to bringing new money into our state, these visitors also help support more than 42,000 Montana jobs and $897 million in worker salaries. (Source: Montana Office of Tourism Annual Report - 2010)\n\r".
			"Please rest assured that these millions of visitors don't come on their own. They are enticed to come here through marketing and outreach done by various organizations that include the Montana Office of Tourism, Glacier Country Regional Tourism Commission and Missoula Convention and Visitor Bureau.\n\r".
			"While there is a 7 percent bed tax collected at all lodging entities in the state, 3 percent supports the General Fund and 4 percent supports travel-related partners. The 4 percent is vital to marketing our stage and it is imperative for that money to remain solely dedicated to travel and tourism promotion. I would urge you to vote no on any bill that would direct any portion of that 4 percent elsewhere.\n\r".
			"Thank you for your consideration in this request and for doing all you can to represent us, your constituents, to the best of your ability. I look forward to hearing from you soon.\n\r".
			"Sincerely,\n".u
			"$name \n".
			"$street \n".
			"$city, $zip \n".
			"$email \\n".
$headers = "From: $email";
mail($to, $subject, $message, $headers);
// SUCCESS!
echo '<p class="notice">'.
	'Thank you for your submission.  '.
 	 '</p>';
// clear out the variables for good-housekeeping
unset($date,$legislator,$bill,$name,$street,$city,$zip,$email);
$_POST = array();
}
?>

<div id="content" class="section">
<?php arras_above_content() ?>

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php arras_above_post() ?>
<div id="post-<?php the_ID() ?>" <?php arras_single_post_class() ?>>
        <?php arras_postheader() ?>
        
        <div class="entry-content clearfix">
<form method="post" action="" id="letter">
<p><label for="name">Date</label>
<input type="text" name="date" id="date" value="<?php echo $_POST['date'];?>"/></p>
<p>Dear Senator/Representative 
<select name="legislator">
<option>Choose a Legislator</option>
<option>Senator John Q. Public</option>
<option>Rep. Jane Q. Public</option>
<option>Some Third Person</option>
</select>,</p>
<p>As a constituent of yours, I urge you to closely review Bill 
<select name="bill">
<option>Choose a Bill</option>
<option>SB 13 / LC0448</option>
<option>LC0505</option>
<option>LC0532</option>
</select>
as it pertains to the distribution and allotment of the 4 percent bed tax collected at lodging properties in Montana.</p>
<p>Tourism is very important to Montana. Not only it is the second largest industry in Montana, it is also a key economic engine for businesses and the thousands of Montanans that have jobs because of tourism.</p>
<p>Nearly 10 million visitors travel to our state each year, contributing between $2.4 billion and $3 billion annually into our economy. In addition to bringing new money into our state, these visitors also help support more than 42,000 Montana jobs and $897 million in worker salaries. (Source: Montana Office of Tourism Annual Report - 2010)</p>
<p>Please rest assured that these millions of visitors don't come on their own. They are enticed to come here through marketing and outreach done by various organizations that include the Montana Office of Tourism, Glacier Country Regional Tourism Commission and Missoula Convention and Visitor Bureau.</p>
<p>While there is a 7 percent bed tax collected at all lodging entities in the state, 3 percent supports the General Fund and 4 percent supports travel-related partners. The 4 percent is vital to marketing our stage and it is imperative for that money to remain solely dedicated to travel and tourism promotion. I would urge you to vote no on any bill that would direct any portion of that 4 percent elsewhere.</p>
<p>Thank you for your consideration in this request and for doing all you can to represent us, your constituents, to the best of your ability. I look forward to hearing from you soon.</p>
<p>Sincerely,<br /> 
<label for="name">Name:</label>
<input type="text" name="name" id="name" value="<?php echo $_POST['name'];?>"/><br />
<label for="email">Street:</label>
<input type="text" name="street" id="street" value="<?php echo $_POST['street'];?>"/><br />
<label for="email">City:</label>
<input type="text" name="city" id="city" value="<?php echo $_POST['city'];?>"/><br />
<label for="email">Zip:</label>
<input type="address" name="zip" id="zip" value="<?php echo $_POST['zip'];?>"/><br />
<label for="email">E-mail:</label>
<input type="text" name="email" id="email" value="<?php echo $_POST['email'];?>"/></p>
<input type="submit" class="button" value="Submit" />
</form>
	<?php the_content( __('<p>Read the rest of this entry »</p>', 'arras') ); ?>  
        <?php wp_link_pages(array('before' => __('<p><strong>Pages:</strong> ', 'arras'), 
		'after' => '</p>', 'next_or_number' => 'number')); ?>
	</div>

 

What do I need to do to get the Email link from the HTML table to pass to the Email variable in the Form?

 

 

 

 

 

Link to comment
Share on other sites

Awesome!! Thank you so much. It is now passing to a second page which just has this code in it for now.

<?php

$test = $_GET['Email'];

echo $test;

?>

 

However now I need to pass it to the form in the previous posted code. How do I go about doing that? Do I just change the $_POST to $_GET? or do I need to have a Separate $_GET statement? FOr instance, just posting this code in the top of the page?

Without the "echo" of course.

 

 

Link to comment
Share on other sites

Ya just post that code in your email script.

 

<?php 

//get email address
$email = $_GET['Email'];

if($_POST){
$to = 'becca@windfallstudio.com';
$subject = "WHAT SHOULD THIS BE";	
$message  =  "Date: $date\n\r".
.............

 

Because you have no url set for the action of your form this will work. The other option is to assign it to a hidden variable in your form.

 

<input type='hidden' name='var_name' value='<?=$_GET['email']?>'>

then you can access it through the POST vars. $_POST['var_name'];

 

 

Link to comment
Share on other sites

For some reason, when I echo on the form page it doesn't even work at all.

 

If I echo it on a blank page, then it works just fine. Hmm.... As if it is ignoring it. Actually, it is ignoring all PHP code anywhere I put it.

 

This is an include on a Wordpress page, should it be done differently.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.