What is wrong with my form code?! First form not working.

9 replies
  • WEB DESIGN
  • |
I have no idea what I'm doing wrong and tutorials are not helping me any further.

This is the code for the html side of the form on my home page (sorry its not colored like in dreamweaver). It appears that when I click submit it knows to go to the php file, and then
it refreshed the page like its suppose to. But everytime I check my email there is nothing
in there.

I have the correct email address in so it seems I must be missing something else in my code.

<form id="form" name="form.php" method="post" action="form.php">
<td width="70" height="34" bgcolor="#EEDB36"><label for="textfield3">
<p class="formtextstyle"> <span class="formtextsmall">Full Name</span></p>
</label></td>
<td width="161" bgcolor="#EEDB36"><input type="text" name="name" id="textfield2" /></td>
</tr>
<tr>
<td bgcolor="#EEDB36">&nbsp;</td>
<td height="34" bgcolor="#EEDB36"><label for="Email" class="formtextstyle"><span class="formtextsmall">Email</span></label></td>
<td bgcolor="#EEDB36"><input type="text" name="Email" id="Email" /></td>
</tr>
<tr>
<td bgcolor="#EEDB36">&nbsp;</td>
<td height="33" bgcolor="#EEDB36"><label for="Phone" class="formtextstyle"><span class="formtextsmall">Phone</span></label></td>
<td bgcolor="#EEDB36"><input type="text" name="Phone" id="Phone" /></td>
</tr>
<tr>
<td bgcolor="#EEDB36">&nbsp;</td>
<td height="89" bgcolor="#EEDB36"><label for="textarea" class="formtextstyle"><span class="formtextsmall">Short Description of Problem</span></label></td>
<td bgcolor="#EEDB36"><textarea name="textarea" id="textarea" cols="15" rows="5"></textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td height="88">&nbsp;</td>
<td><input type="submit" name="button" id="button" value="send" /></form></td>


Then this is my php script which I named "form.php"

<?php
/* Email Variables */
$emailSubject = 'form';
$webMaster = 'rcece1@yahoo.com';

/* Data Variables */
$email = $_POST['email'];
$name = $_POST['name'];
$phone = $_POST['phone'];

$body = <<<EOD
<br><hr><br>
Name: $name <br>
Email: $email <br>
Comments: $phone <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>
<head>
<title>sent message</title>
<meta http-equiv="refresh" content="3;URL=http://www.allcountywaterproofing.com">
<style type="text/css">
<!--
body {
background-color: #444;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 20px;
font-style: normal;
line-height: normal;
font-weight: normal;
color: #fec001;
text-decoration: none;
padding-top: 200px;
margin-left: 150px;
width: 800px;
}
-->
</style>
</head>
<div align="center">Your email will be answered soon as possible!
You will return to All County Waterproofing now!</div>
</div>
</body>
</html>
EOD;
echo "$theResults";
?>


My home page is located at All County Waterproofing

I also have no idea why the top box of the form is showing the way it is. At some point it was where it was suppose to be, then I tried to make the form work by changing code around and it seems I'm just making things worse.

If anyone is able to tell what I am doing wrong you would save me so much time and I'd really be indebted to you forever. I have never wasted so much time on a form before I'm really losing my mind.

=[
#code #form #working #wrong
  • Profile picture of the author RedShifted
    Look I know its a lot of data to go through but I also know someone on this forum knows the solution.
    PLEASE UNDERSTAND I wasted A LOT of time and am truely stuck. I need to get this done asap and this has probably been a week in total I've been playing around with this stupid form. Or if you don't know, can someone at least point me in the direction of where I can go to pay someone? I don't need to pay someone to build a whole site it would be just for small little problems like this that seem to happen all the time.

    If ANYONE could please just take a look at the code or help me save time (by telling me where I need to go) I'd be SOO THANKFUL. =]
    {{ DiscussionBoard.errors[5821736].message }}
    • Profile picture of the author Brandon Tanner
      Just from a quick look at your form.php code, it looks like you're missing quotes in a few places.

      For example, wrap double quotes around the $body string, like this...

      $body = "<<<EOD
      <br><hr><br>
      Name: $name <br>
      Email: $email <br>
      Comments: $phone <br>
      EOD";


      And the $theresults string should have *single* quotes wrapped around it (double quotes won't work here, because you already have double quotes inside that string). So it should start with...

      $theResults = '<<<EOD

      and end with...

      EOD';

      And, on the last line, there's no need for quotes here, so you could just do this...

      echo $theResults;

      And, $_POST values are case-sensitive. So since you have them all lower-case in your PHP code, you should make those values lower-case in your HTML code as well. For example...

      <td bgcolor="#EEDB36"><input type="text" name="email" id="Email" /></td>

      <td bgcolor="#EEDB36"><input type="text" name="phone" id="Phone" /></td>


      Also... just out of curiosity, what is "EOD" for?
      Signature

      {{ DiscussionBoard.errors[5825407].message }}
  • Profile picture of the author RedShifted
    Ok so what I wound up doing was I took a previous form I made that I KNEW was working on another site, and found out that form doesn't work either on these new servers.

    So now I'm assuming the form code might not be the problem since you guys don't seem to be finding anything critical.

    My question now would have to be. If php is enabled on the servers, and this form winds up working on different servers, what in the world could the problem be?

    Do I need a 3rd file or something? Are servers different in terms of how forms are run? I have no idea why one form works on one server but not this new server I'm working on. Like I said php scripting is enabled so I have no idea what could be causing this.

    As far as what "EOD" means your guess is as good as mine. I got this form from a youtube tutorial and just tried to add fields to it & the php script. I think the ultimate test will be whether or not it works on my other servers, so I'm going to test that out right now.
    {{ DiscussionBoard.errors[5827536].message }}
  • Profile picture of the author Kingfish85
    Why not just use something like JotForm instead... you could have been done.
    Signature

    |~| VeeroTech Hosting - sales @ veerotech.net
    |~| High Performance CloudLinux & LiteSpeed Powered Web Hosting
    |~| cPanel & WHM - Softaculous - Website Builder - R1Soft - SpamExperts
    |~| Visit us @veerotech Facebook - Twitter - LinkedIn

    {{ DiscussionBoard.errors[5827619].message }}
  • Profile picture of the author Brandon Tanner
    Originally Posted by kcartlidge View Post

    No, no, don't add the quotes. I'll have a fuller look but just thought I'd do a quick post to stop you doing that. The syntax used is known as heredoc and does not use quotes.
    OK... I stand corrected. I've been programming w/ PHP for several years and I've never even heard of "heredoc", until now. Just goes to show how vast PHP is. Good call, kcartlidge!
    Signature

    {{ DiscussionBoard.errors[5828288].message }}
  • Profile picture of the author CMSBunny
    Greetings RedShifted,

    I'd suggest you go to CMSHelpLive. You can submit a support ticket and they will contact you within 1 hour.
    {{ DiscussionBoard.errors[5837942].message }}

Trending Topics