Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 296
  • Last Modified:

Help with html/php contact form

I'm having trouble with a contact form on a website. Please visit this site: www.mwebdev.com/par and go to the Contact Us page. I have a contact.php form set up with the correct field names etc. The same php file works on other sites, but I can't get it to work here. Its supposed to go to a Message Sent page when the message is submitted. Neither the Reset or Submit buttons work. Thanks in advance.
0
isaacr25
Asked:
isaacr25
  • 7
  • 6
1 Solution
 
Jason C. LevineNo oneCommented:
Hi again isaac.

There is almost no way to troubleshoot this without the php and html code involved.

As a wild guess, I would point towards using images as buttons and the php script is not detecting the submit properly.
0
 
isaacr25Author Commented:
Here is the php code:

<?php


// get posted data into local variables
$EmailFrom = "-removed-";
$EmailTo = "-removed-";
$Subject = "-removed-";
$Name = Trim(stripslashes($_POST['Name']));
$Phone = Trim(stripslashes($_POST['Phone']));
$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 .= "Phone: ";
$Body .= $Phone;
$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=sent.html\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>

And here is the form code:

<td valign="top" width="253" height="241" style="background:url(images/1_bg2.gif) repeat-x top; background-color:#7F95AE ">                                                                                                         <div style=" margin:24 0 0 21px; line-height:14px " class="w"><input name="Name" type="text"  class="w" id="Name" style="width:210px; height:25px;  " value=" &nbsp;your name"  >
                                                <br><input name="Email" type="text"  class="w" id="Email" style="width:210px; height:25px; " value=" &nbsp;e-mail" >
                                                <br><input name="Phone" type="text"  class="w" id="Phone" style="width:210px; height:25px; " value=" &nbsp;phone" >
                                                <br><textarea name="Message"  cols="35" rows="35" class="w" id="Message" style="width:210px; height:90px; overflow:hidden "> &nbsp;message</textarea>
                                                </div>
 <form action="" id="form" style="margin:0; padding:0 ">
                                                                                                      <div style="margin:12 15 0 88px;"><input name="clear" type="image" id="clear" style=" border-style:none  " src="images/6_k1.gif" onClick="this.form.reset(); return false;"><input name="submit"  type="image" id="submit" style="border-style:none; margin-left:16px "  src="images/6_k2.gif" >
                                                                                                      </div>
</form>
                                                </td>
0
 
gamebitsCommented:
Your form opening tag should go before your first input tag
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
isaacr25Author Commented:
gamebits,

I've tried that with no success:

<td valign="top" width="253" height="241" style="background:url(images/1_bg2.gif) repeat-x top; background-color:#7F95AE ">                                                                                                         <div style=" margin:24 0 0 21px; line-height:14px " class="w"><form action="" id="form" style="margin:0; padding:0 ">
                                                  <div align="center">
                                                    <input name="Name" type="text"  class="w" id="Name" style="width:210px; height:25px;  " value=" &nbsp;your name"  >
                                                    <br>
                                                    <input name="Email" type="text"  class="w" id="Email" style="width:210px; height:25px; " value=" &nbsp;e-mail" >
                                                    <br>
                                                    <input name="Phone" type="text"  class="w" id="Phone" style="width:210px; height:25px; " value=" &nbsp;phone" >
                                                    <br>
                                                    <textarea name="Message"  cols="35" rows="35" class="w" id="Message" style="width:210px; height:90px; overflow:hidden "> &nbsp;message</textarea>
                                                    </div>
                                                </div>
                                                  <div style="margin:12 15 0 88px;">
                                                    <div align="center">
                                                      <input name="clear" type="image" id="clear" style=" border-style:none  " src="images/6_k1.gif" onClick="this.form.reset(); return false;">
                                                      <input name="submit"  type="image" id="submit" style="border-style:none; margin-left:16px "  src="images/6_k2.gif" >
                                                  </div>
                                                  </div>
</form>                                            </td>
0
 
Jason C. LevineNo oneCommented:
<form action=""

There needs to be a form action.  Either it points to the script if the script is in a separate file or it points to the same file as the form if the script is embedded in that file.
0
 
isaacr25Author Commented:
Jason,
    I added the name of the php script for the form action, and I'm getting an email now. However, none of the field values are being transmitted in the email.
0
 
Jason C. LevineNo oneCommented:
Did you move the form tag up so that it appears before all the input tags?
0
 
isaacr25Author Commented:
Yes,
    Here's my form code now:

<form action="contact.php" id="form" style="margin:0; padding:0 ">
                                                  <div align="center">
                                                    <input name="Name" type="text"  class="w" id="Name" style="width:210px; height:25px;  " value=" &nbsp;your name"  >
                                                    <br>
                                                    <input name="Email" type="text"  class="w" id="Email" style="width:210px; height:25px; " value=" &nbsp;e-mail" >
                                                    <br>
                                                    <input name="Phone" type="text"  class="w" id="Phone" style="width:210px; height:25px; " value=" &nbsp;phone" >
                                                    <br>
                                                    <textarea name="Message"  cols="35" rows="35" class="w" id="Message" style="width:210px; height:90px; overflow:hidden "> &nbsp;message</textarea>
                                                  </div>
                                                  <div style="margin:12 15 0 88px;"><input name="clear" type="image" id="clear" style=" border-style:none  " src="images/6_k1.gif" onClick="this.form.reset(); return false;"><input name="submit"  type="image" id="submit" style="border-style:none; margin-left:16px "  src="images/6_k2.gif" >
                                                  </div>
</form>
0
 
Jason C. LevineNo oneCommented:
So what happens now?  Does the email send when the form is submitted or when the page is loaded?
0
 
isaacr25Author Commented:
The email sends, but with no values, only the field labels from the php file. The php file is being run correctly, but the field values aren't being sent in the email.
0
 
Jason C. LevineNo oneCommented:
Are the files separate or is the php embedded in the same file as the form?
0
 
isaacr25Author Commented:
Contact.php is a separate php file that resides in the same directory.
0
 
Jason C. LevineNo oneCommented:
duh.  I'm tired tonight and missed the obvious.  Sorry...

Issac, your PHP is looking for POST variables.

Here's the form tag:

<form action="contact.php" id="form" style="margin:0; padding:0 ">

See something missing?

Try:

<form action="contact.php" id="form" style="margin:0; padding:0" method="post">

Thank you, and good night.  I'm going to go have a beer and forget that I know how to do web stuff for a while.
0
 
isaacr25Author Commented:
You deserve it. Thanks!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now