Results 1 to 6 of 6

Thread: Forms coming through blank

  1. #1
    Join Date
    Aug 2009
    Location
    London
    Posts
    93
    Thanks
    26
    Thanked 0 Times in 0 Posts

    Default Forms coming through blank

    Hi,

    I'm trying to create a website 'Contact' form using PHP for the first time. I found a free form online that I have adapted for my own purposes.

    So to verify, I have my contact.html file and another called contactengine.php.

    When I upload these files to my server and test it online, I get the form message, but the info I typed-in does not show - it is blank.

    Please can anyone make any suggestions why this maybe?

    Thanks in anticipation of your replies!

    HTML Code:
    <div id="formcontainer"> 
       <form id="comments_form" action="contactengine.php"> 
    <fieldset> 
      <legend>Contact:</legend> 
      <p> 
      <label for="Name">Name: </label> 
      <input type="text" name="Name" id="Name" /> 
      </p> 
      
      <p> 
      <label for="Email">Email Address: </label> 
       <input type="text" name="Email" id="Email" /> 
      </p> 
      
      <p> 
      <label for="Message">Message:</label> 
    <textarea name="Message" rows="10" cols="20" id="Message"> 
    </textarea> 
      </p> 
      
      <div> 
    <input type="submit" name="Submit" id="Submit" value="Submit" class="btn" /> 
    </div> 
      
    </fieldset> 
    
    </form>    
     </div>
    PHP Code:
    <?php 

    $EmailFrom 
    "johnhathwayatwaitrose.com"
    $EmailTo "johnatjohnhathway.co.uk"
    $Subject "A Message From Your Website"
    $Name Trim(stripslashes($_POST['Name'])); 
    $Tel Trim(stripslashes($_POST['Tel'])); 
    $Email Trim(stripslashes($_POST['Email'])); 
    $Message Trim(stripslashes($_POST['Message'])); 

    // validation 
    $validationOK=true
    if (!
    $validationOK) { 
      print 
    "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"
      exit; 


    // prepare email body text 
    $Body ""
    $Body .= "Name: "
    $Body .= $Name
    $Body .= "\n"
    $Body .= "Tel: "
    $Body .= $Tel
    $Body .= "\n"
    $Body .= "Email: "
    $Body .= $Email
    $Body .= "\n"
    $Body .= "Message: "
    $Body .= $Message
    $Body .= "\n"

    // send email 
    $success mail($EmailTo$Subject$Body"From: <$EmailFrom>"); 

    // redirect to success page 
    if ($success){ 
      print 
    "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">"

    else{ 
      print 
    "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"

    ?>

  2. #2
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    Before you test the php code, try adding this to your <form> tag:
    Code:
    <form id="comments_form" action="contactengine.php" method="post">
    If that doesn't work, comment out your redirection script and just put echo $Name; somewhere just to check if it is going through...
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  3. #3
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    By default the form will come through in the $_GET array, but it's best to go with the post option. You could also try using the $_REQUEST array if you still don't get any data, as this should give the greatest chance of pulling something through.

    I imagine changing the method to "post" will solve this though.

  4. #4
    Join Date
    Aug 2009
    Location
    London
    Posts
    93
    Thanks
    26
    Thanked 0 Times in 0 Posts

    Default

    Hi,

    Thanks for your replies.

    I changed it to the following and now it works OK

    HTML Code:
    <form method="Post" action="contactengine.php">

    But..... I generated a second form utilising this one once we got it working, I created two new fields - one of them works OK but the other is still coming through blank.

    The 'Journal' field comes through blank.

    One interesting thing: the 'Tel' field was originally called 'Telephone' and it didn't work, but then I shortened it to 'Tel' and it worked OK!?!?

    Do you guys have any suggestions please?

    HTML Code:
    <div id="formcontainer">
       <form method="Post" action="pressengine.php">
    
    <fieldset>
      <legend>For press and media requests, please fill in the the form below.</legend>
      <p>
      <label for="Name">Name: </label>
      <input type="text" name="Name" id="Name" />
      </p>
      
       <p>
      <label for="Journal">Journal: </label>
      <input type="text" name="Journal" id="Journal" />
      </p>
      
      <p>
      <label for="Email">Email Address: </label>
    	<input type="text" name="Email" id="Email" />
      </p>
      
      <p>
      <label for="Tel">Tel:</label>
    	<input type="text" name="Tel" id="Tel" />
      </p>
      
      <p>
      <label for="Message">Message:</label>
    <textarea name="Message" rows="10" cols="20" id="Message">
      </textarea>
      </p>
      
      <div>
    <input type="Submit" name="Submit" id="Submit" value="Submit" class="btn" />
    </div>
      
    </fieldset>
    
    </form>   
     </div>
    pressengine.php:
    PHP Code:
    <?php

    $EmailFrom 
    "johnhathway@waitrose.com";
    $EmailTo "john@johnhathway.co.uk";
    $Subject "A Press Enquiry";
    $Name Trim(stripslashes($_POST['Name']));
    $Email Trim(stripslashes($_POST['Journal'])); 
    $Email Trim(stripslashes($_POST['Email'])); 
     
    $Tel Trim(stripslashes($_POST['Tel'])); 
    $Message Trim(stripslashes($_POST['Message'])); 

    // validation
    $validationOK=true;
    if (!
    $validationOK) {
      print 
    "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
      exit;
    }

    // prepare email body text
    $Body "";
    $Body .= "Name: ";
    $Body .= $Name;
    $Body .= "\n";
    $Body .= "Journal: ";
    $Body .= $Journal;
    $Body .= "\n";
    $Body .= "Email: ";
    $Body .= $Email;
    $Body .= "\n";
    $Body .= "Tel: ";
    $Body .= $Tel;
    $Body .= "\n";
    $Body .= "Message: ";
    $Body .= $Message;
    $Body .= "\n";

    // send email 
    $success mail($EmailTo$Subject$Body"From: <$EmailFrom>");

    // redirect to success page 
    if ($success){
      print 
    "<meta http-equiv=\"refresh\" content=\"0;URL=pressthanks.php\">";
    }
    else{
      print 
    "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
    }
    ?>

  5. #5
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    This is caused by a simple mistake where you have changed the same variable twice. Look closely here:

    PHP Code:
    $Email Trim(stripslashes($_POST['Journal'])); 
    $Email Trim(stripslashes($_POST['Email'])); 
    $_POST['Journal'] is being assigned to the $email variable, and then the $email variable is changed to hold a different value on the next line, that is why you don't see the $Journal variable coming through.

    Change to:

    PHP Code:
    $Journal Trim(stripslashes($_POST['Journal'])); 
    $Email Trim(stripslashes($_POST['Email'])); 
    And you should be sorted.

    You may also want to set your error reporting to a higher level, as it would have warned you about this:

    PHP Code:
    NoticeUndefined variableJournal in "YOUR FILE HERE"  on line X 
    Last edited by Schmoopy; 03-16-2010 at 03:06 PM.

  6. The Following User Says Thank You to Schmoopy For This Useful Post:

    jhatter (03-16-2010)

  7. #6
    Join Date
    Aug 2009
    Location
    London
    Posts
    93
    Thanks
    26
    Thanked 0 Times in 0 Posts

    Default

    Thanks Schmoopy, it's good to have people like you around. Everything is working now!

Bookmarks

Posting Permissions

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