#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Posts
    23
    Rep Power
    0

    Pass subject from link to contact form?


    Hi, does anyone know how to pass the subject from a link to the contact form page that it links to? Thanks, I appreciate your help.

    Edit: It doesn't necessarily have to be PHP.
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,237
    Rep Power
    9400
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Posts
    23
    Rep Power
    0
    I want to be able to link to contact.php (the page that has the form on it), and have the subject field passed from the link that they clicked to get there.
  6. #4
  7. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,237
    Rep Power
    9400
    Sure: stick the subject line in the URL like
    Code:
    contact.php?subject=This%20is%20the%20subject%20line
    remembering to use rawurlencode() to get it in there properly, then have your contact.php check $_GET["subject"] for a default value.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Posts
    23
    Rep Power
    0
    Originally Posted by requinix
    Sure: stick the subject line in the URL like
    Code:
    contact.php?subject=This%20is%20the%20subject%20line
    remembering to use rawurlencode() to get it in there properly, then have your contact.php check $_GET["subject"] for a default value.
    Thanks, can someone please help me out with the code to make this work? This is what I'm using to send the form:

    PHP Code:
    <?php

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

    // EDIT THE 2 LINES BELOW AS REQUIRED

    $email_to "email@email.com";

    $email_subject "Subject here";

    function 
    died($error) {

    // your error code can go here

    echo "Sorry, but there were error(s) found with the form you submitted. ";

    echo 
    "<br /><br />";

    echo 
    $error."<br /><br />";

    echo 
    "Please go back and fix these errors.<br /><br />";

    die();

    }

    // validation expected data exists

    if(!isset($_POST['email']) ||

    !isset(
    $_POST['comments'])) {

    died('Sorry, but there appears to be a problem with the form you submitted.'); 

    }

    $email_from $_POST['email']; // required

    $comments $_POST['comments']; // required

    $error_message "";

    $email_exp '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';

    if(!
    preg_match($email_exp,$email_from)) {

    $error_message .= 'The email address you entered does not appear to be valid.<br />';

    }

    if(
    strlen($comments) < 2) {

    $error_message .= 'The comments you entered do not appear to be valid.<br />';

    }

    if(
    strlen($error_message) > 0) {

    died($error_message);

    }

    $email_message "Form details below.\n\n";

    function 
    clean_string($string) {

    $bad = array("content-type","bcc:","to:","cc:","href");

    return 
    str_replace($bad,"",$string);

    }

    $email_message .= "Name: ".clean_string($realname)."\n";

    $email_message .= "Email: ".clean_string($email_from)."\n";

    $email_message .= "Comments: ".clean_string($comments)."\n";

    // create email headers

    $headers 'From: '.$email_from."\r\n".

    'Reply-To: '.$email_from."\r\n" .

    'X-Mailer: PHP/' phpversion();

    @
    mail($email_to$email_subject$email_message$headers); 



    header ('Location: http://www.site.com/thankyou.htm');

    exit();



    }

    ?>

    here is the form:
    PHP Code:
    <form name="contactform" method="post" action="send_form_email.php">
    <
    input name="realname" type="text" size="26">
    <
    input name="subject" type="text" size="26">
    <
    input name="email" type="text" size="26">
    <
    textarea name="comments" cols="20" rows="12"></textarea>
    <
    input name="Submit" type="image" value="Submit" src="send.gif" alt="Send" width="112" height="23"
    Right now the subject is not even being passed.

    Thanks!
  10. #6
  11. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,237
    Rep Power
    9400
    If you're still talking about getting the subject in there on the first page load then of course it won't work now: you're not even trying. Add some code like how I suggested, then we can talk about why it might not work.
  12. #7
  13. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    The subject is already moving between pages, you have it right there in POST. You use other POST variables in this code, so it shouldn't be hard to track down.

    Are you not a PHP programmer? It looks like you got this page from someone else.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo