Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-08-2010, 03:36 AM   PM User | #1
rjkdonaldson
Regular Coder

 
Join Date: May 2007
Location: Indonesia
Posts: 163
Thanks: 10
Thanked 0 Times in 0 Posts
rjkdonaldson is an unknown quantity at this point
Appending variables to contact page

Hi,

I need help with appending variables to my php contact page. I have a php page with some products on it and would like the data sent to the textarea of the contact page when the inquire link is clicked. Could someone kindly provide the steps on doing this. Thanks.
rjkdonaldson is offline   Reply With Quote
Old 12-08-2010, 03:45 AM   PM User | #2
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,045
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
You can start by showing us the pages involved ... like a link to your website.
We need to see the products page and the contact page.

I have one question though,
Does the user go back and forth between the two pages and they can keep adding items to their inquiry?
mlseim is offline   Reply With Quote
Old 12-08-2010, 03:51 AM   PM User | #3
rjkdonaldson
Regular Coder

 
Join Date: May 2007
Location: Indonesia
Posts: 163
Thanks: 10
Thanked 0 Times in 0 Posts
rjkdonaldson is an unknown quantity at this point
Hi, no the page doesn't involve a cart whatsoever, I would probably add that functionality later though. Here is the packages page that gets the stuff from the db.

PHP Code:
<html>
<title>Kite Surfing Safaris</title>

<head>



<link href="../includes/css.css" rel="stylesheet" type="text/css" />
</head>
<body><marquee><div align="center" style="color:#ffffff; font-

size:18px;">KiteSurfingSafaris</div></marquee>

<div id="kiteboarder"></div>
<?php include("menu_top.html"); ?>

<table width="640px" height="100%" align="center" valign="top" id="content" 

border="0px"><tr><td valign="top"><div style="color:#ff9900; font-size:18px;"><h3 

style="color:#800000;">Packages</h3>
<?php
// Make a MySQL Connection
mysql_connect("localhost""""") or die(mysql_error());
mysql_select_db("products") or die(mysql_error());

// Get all the data from the "package" table
$result mysql_query("SELECT * FROM package"
or die(
mysql_error());  


echo 
"<center><table border='1'>";
echo 
"<tr bgcolor='#ffff99'><th>Name</th> <th>Description</th><th>Price</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['p_name'];
    echo 
"</td><td>"
    echo 
$row['p_description'];
        echo 
"</td><td>$";
         echo 
$row['p_price'];
         echo 
"</td><td><div><a href='#'>Inquire</a></div>";     
    echo 
"</td></tr>"
  


echo 
"</table></center>";
?>
</td></tr></table></div></body>
</html>
The following is the contact page
PHP Code:
<?php
define
("EMAIL""youremail@yourdomain.com");

if(isset(
$_POST['submit'])) {

  include(
'validate.class.php');

  
//assign post data to variables
  
$fname trim($_POST['firstname']);
  
$lname trim($_POST['lastname']);
    
$email trim($_POST['email']);
    
$message trim($_POST['message']);

  
//start validating our form
  
$v = new validate();
  
$v->validateStr($fname"first name"375);
  
$v->validateStr($lname"last name"375);
  
$v->validateEmail($email"email");
  
$v->validateStr($message"message"51000);  

  if(!
$v->hasErrors()) {
        
$header "From: $email\n" "Reply-To: $email\n";
        
$subject "Contact Form Subject";
        
$email_to EMAIL;

        
$emailMessage "First Name: " $fname "Last Name: " $lname "\n";
        
$emailMessage .= "Email: " $email "\n\n";
        
$emailMessage .= $message;

    
//use php's mail function to send the email
        
@mail($email_to$subject ,$emailMessage ,$header );  

    
//grab the current url, append ?sent=yes to it and then redirect to that url
        
$url "http". ((!empty($_SERVER['HTTPS'])) ? "s" "") . "://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
        
header('Location: '.$url."?sent=yes");

    } else {
    
//set the number of errors message
    
$message_text $v->errorNumMessage();        

    
//store the errors list in a variable
    
$errors $v->displayErrors();

    
//get the individual error messages
    
$fnameErr $v->getError("first name");
    
$lnameErr $v->getError("last name");
    
$emailErr $v->getError("email");
    
$messageErr $v->getError("message");
  }
//end error check
}// end isset
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="robots" content="noindex, nofollow"/>
<title>Kite Surfing Safaris</title>

<link href="../includes/css.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="kiteboarder"></div>
<?php include("menu_top.html"); ?>

<table width="50%" height="100%" align="center" valign="top" id="content" border="0px"><tr><td valign="top">     <p><div style="color:#ff9900; font-size:18px;"><a href="mailto:sales@kitesurfingsafaris.com.au">sales@kitesurfingsafaries.com.au</a><br/>If you would like to inquire about our services please fill in the form below with your details and we will get in touch with you as quickly as possible.</div></p><br/>
  <div id="contact_form_wrap"><fieldset><legend>Contact Us</legend>
    <span class="message"><?php echo $message_text?></span>
    <?php echo $errors?>
    <?php if(isset($_GET['sent'])): ?><h2>Your message has been sent</h2><?php endif; ?>
    <form id="contact_form" method="post" action="/contact3.php">
      <p><label>First Name:<br />
      <input type="text" name="firstname" class="textfield" value="<?php echo htmlentities($fname); ?>" />
      </label><br /><span class="errors"><?php echo $fnameErr?></span></p>
      
      <p><label>Last Name:<br />
      <input type="text" name="lastname" class="textfield" value="<?php echo htmlentities($lname); ?>" />
      </label><br /><span class="errors"><?php echo $lnameErr?></span></p>

      <p><label>Email: <br />
      <input type="text" name="email" class="textfield" value="<?php echo htmlentities($email); ?>" />
      </label><br /><span class="errors"><?php echo $emailErr ?></span></p>          

      <p><label>Message: <br />
      <textarea name="message" class="textarea" cols="45" rows="5"><?php echo htmlentities($message); ?></textarea>
      </label><br /><span class="errors"><?php echo $messageErr ?></span></p>

      <p><input type="submit" name="submit" class="button" value="Submit" /></p>
    </form>
  </fieldset>

</div>

</td></tr>
</table>

</body>
</html>

Last edited by rjkdonaldson; 12-08-2010 at 04:08 AM..
rjkdonaldson is offline   Reply With Quote
Old 12-08-2010, 03:58 AM   PM User | #4
rjkdonaldson
Regular Coder

 
Join Date: May 2007
Location: Indonesia
Posts: 163
Thanks: 10
Thanked 0 Times in 0 Posts
rjkdonaldson is an unknown quantity at this point
In response to your question earlier is that the better approach? I would just suggest the data that is retrieved from the db to sit in the textarea of the contact form then the user can add additional info if need be.

Last edited by rjkdonaldson; 12-08-2010 at 04:14 AM..
rjkdonaldson is offline   Reply With Quote
Old 12-08-2010, 12:58 PM   PM User | #5
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,045
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
This line:
echo "</td><td><div><a href='#'>Inquire</a></div>";

Will be:
echo "</td><td><div><a href='contact.php?inq={$row['p_name']}'>Inquire</a></div>";


Then, in contact.php, you'll get that variable

$inquiry=$_GET['inq'];

You can do whatever you want with it there.
mlseim is offline   Reply With Quote
Users who have thanked mlseim for this post:
rjkdonaldson (12-08-2010)
Old 12-08-2010, 09:35 PM   PM User | #6
rjkdonaldson
Regular Coder

 
Join Date: May 2007
Location: Indonesia
Posts: 163
Thanks: 10
Thanked 0 Times in 0 Posts
rjkdonaldson is an unknown quantity at this point
Hey mlseim I tried to get the value from the db to show in the textarea of the contact form but the php code gets output instead. This is what I get in the textarea of the form $inquiry=$_GET['inq'];> I have also wrapped the php tags around this bit of code
rjkdonaldson is offline   Reply With Quote
Old 12-08-2010, 09:47 PM   PM User | #7
rjkdonaldson
Regular Coder

 
Join Date: May 2007
Location: Indonesia
Posts: 163
Thanks: 10
Thanked 0 Times in 0 Posts
rjkdonaldson is an unknown quantity at this point
It worked msliem, thanks bud.
rjkdonaldson is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:17 PM.


Advertisement
Log in to turn off these ads.