We help IT Professionals succeed at work.

Help with html/php contact form

isaacr25
isaacr25 asked
on
331 Views
Last Modified: 2012-05-05
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.
Comment
Watch Question

Jason C. LevineDon't talk to me.
CERTIFIED EXPERT

Commented:
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.

Author

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>
CERTIFIED EXPERT

Commented:
Your form opening tag should go before your first input tag

Author

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>
Jason C. LevineDon't talk to me.
CERTIFIED EXPERT

Commented:
<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.

Author

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.
Jason C. LevineDon't talk to me.
CERTIFIED EXPERT

Commented:
Did you move the form tag up so that it appears before all the input tags?

Author

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>
Jason C. LevineDon't talk to me.
CERTIFIED EXPERT

Commented:
So what happens now?  Does the email send when the form is submitted or when the page is loaded?

Author

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.
Jason C. LevineDon't talk to me.
CERTIFIED EXPERT

Commented:
Are the files separate or is the php embedded in the same file as the form?

Author

Commented:
Contact.php is a separate php file that resides in the same directory.
Don't talk to me.
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
You deserve it. Thanks!

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.