Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    May 2007
    Location
    Indonesia
    Posts
    164
    Thanks
    10
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,471
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    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?

  • #3
    Regular Coder
    Join Date
    May 2007
    Location
    Indonesia
    Posts
    164
    Thanks
    10
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Regular Coder
    Join Date
    May 2007
    Location
    Indonesia
    Posts
    164
    Thanks
    10
    Thanked 0 Times in 0 Posts
    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.

  • #5
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,471
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    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.

  • Users who have thanked mlseim for this post:

    rjkdonaldson (12-08-2010)

  • #6
    Regular Coder
    Join Date
    May 2007
    Location
    Indonesia
    Posts
    164
    Thanks
    10
    Thanked 0 Times in 0 Posts
    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

  • #7
    Regular Coder
    Join Date
    May 2007
    Location
    Indonesia
    Posts
    164
    Thanks
    10
    Thanked 0 Times in 0 Posts
    It worked msliem, thanks bud.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •