Skip to main content
October 1, 2011
Question

Please Help PHP Problem Submitting Form

  • October 1, 2011
  • 1 reply
  • 516 views

Hi there,

I am a complete web design novice, but am trying to finish off a site for my small video production business.

I am using Dreamweaver CS3 and been following tutorials up to this point, but am stuck on the last part which is submitting a form. After following a tutorial, I got the submit button to work (send a message to my e-mail), however all the field are blank as opposed to having text within their fields. I have put below the script both of my form, and of my PHP document:

Form:

<form action="phptest.php" name="ContactForm" target="_blank" id="ContactForm">

                                          <div>

                                                                      <div class="wrapper"><div class="bg"><input name="Name" type="text" class="input" id="Name" onFocus="if(this.value =='Name' ) this.value=''"  onblur="if(this.value=='') this.value='Name'" value="Name" >

                                                                      </div></div>

                                                                      <div class="wrapper"><div class="bg"><input name="email" type="text" class="input" id="email" onFocus="if(this.value =='E-mail' ) this.value=''"  onblur="if(this.value=='') this.value='E-mail'" value="E-mail" ></div></div>

                                                                      <div class="wrapper"><div class="bg2"><textarea name="questions" cols="1" rows="1" id="questions" onFocus="if(this.value =='Questions/Comments' ) this.value=''" onBlur="if(this.value=='') this.value='Questions/Comments'"  >Questions/Comments</textarea></div></div>

                                                                      <div class="wrapper">

                                                                        <table width="300" border="1">

                                <tr>

                                  <td><input name="reset" type="reset" class="button" id="reset2" accesskey="r" tabindex="140" value="reset"></td>

                                  <td><input name="submit2" type="submit" class="button" id="submit2" accesskey="s" tabindex="160" value="submit"></td>

                                </tr>

                              </table>

                                                                        </div>

                                                            </div>

                                                            </form>

PHP DOC:

<?php

/* Email test */

          $emailSubject = 'Crazy PHP Scripting!';

          $webMaster = 'info@dcmcvideography.ca';

 

/* Gathering Data Variables */

          $NameField = $_POST['Name'];

          $emailField = $_POST['email'];

          $questionsField = $_POST['questions'];

 

          $body = <<<EOD

<br><hr><br>

Name: $Name <br>

Email: $email <br>

Questions: $questions <br>

EOD;

          $headers = "From: $email\r\n";

          $headers .= "Content-type: text/html\r\n";

          $success = mail($webMaster, $emailSubject, $body, $headers);

 

/* Results rendered as HTML */

          $theResults = <<<EOD

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

</head>

<body>Hello Thanks

</body>

</html>

EOD;

echo "$theResults";

?>

Any help would be greatly appreciated. Thanks!

This topic has been closed for replies.

1 reply

MurraySummers
Inspiring
October 1, 2011

You aren't using the correct variable names!

Try this -

<br><hr><br>

Name: $NameField <br>

Email: $emailField <br>

Questions: $questionsField <br>

EOD;

By the way, sending emails out without trying to remove 'bad characters' is not a good idea.  At the least, you should do something like -

          $NameField = stripslashes(strip_tags($_POST['Name']));

          $emailField = stripslashes(strip_tags($_POST['email']));

          $questionsField = stripslashes(strip_tags($_POST['questions']));

It wouldn't hurt to use a regex to test whether the email format is correct also.  Here's an example -

// check for valid email address

$pattern = '/^[^@]+@[^\s\r\n\'";,@%]+$/';

if (!preg_match($pattern, trim($emailField))) {

  $error['email'] = 'Please enter a valid email address';

  } 

October 1, 2011

Thank you for all your help!

I still can't seem to get it to work though... The primary script you gave me,

<br><hr><br>

Name: $NameField <br>

Email: $emailField <br>

Questions: $questionsField <br>

EOD;

I believe is the exact same as what I already had in my PHP document, or am I suppose to put it somewhere else? (again sorry I am a complete novice).

Also on a side note, do you know the script I have to change to make the page that appears after the submit button is clicked, appear in the same tab as opposed to opening a new tab? Thanks!

Aaron