Inseritng a php form

Soldato
Joined
5 Aug 2003
Posts
8,535
Location
Essex
I've completely forgotten how to do this but I want to insert a php email form on an html page, the form in question is an email form where people enter their name, email address and message but I can't for the life of me remember how to insert it on the html page.

edit/ I know I spelt inserting wrong lol
 
so let me get this straight. You have a html form and you want to inserit some php? or do you have both but can't remember how to put them in the code?

here is a php contact form from my site
Code:
            <?php
if ($_POST['formsent'] == "1")
{
  $email = $_POST['email'];
  $subject = $_POST['subject'];
  $youremail = $_POST['replyto'];
  $message = $_POST['message'];
  if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email))
  {
    echo "The e-mail was not valid. Please go back and try again.";
  }
  else
  {
    if($subject == "")
    {
      echo "You must enter a email subject";
    }
    else
    {
      if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $youremail))
      {
        echo "Your e-mail was not valid. Please go back and try again.";
      }
      else
      {
       if($_POST["url"] != "")
        {
            exit;
        }
        else
        {
            if ($message == "")
            {
            echo "You must enter a message";
            }
            else
            {
          
            $headers = "From: ".$youremail;
            mail($email,$subject,$message,$headers);
            echo "
Thank you for filling out the online form. I will get back to you very soon.
          
            
            ";
                }
        }
      }
    }
  }
}
else
{
?>


If you need to contact me please use the online form below and I will get back to you as soon as possible.

<br /><br >

<hr />

<br />

<form action="contact.php" method="post">

<table width="520px" align="left" cellpadding="0" cellspacing="10"  class="txt" style="border: 0px">

    <input type="hidden" name="formsent" value="1" />
    <input type="hidden" name="email" value="email address here" />
                  
                  <tr>
                    <td  align="left" valign="middle" width="115px"><b>Name :</b></td>
                    <td width="400px"><input type="text" name="subject" value="" /></td>
                  </tr>
                  
                  <tr>
                    <td  align="left" valign="middle" width="115px"><b>Email Address :</b></td>
                    <td width="400px"><input type="text" name="replyto" value="" /></td>
                  </tr>
                  
                  
                  <tr>
                    <td  align="left" valign="top" width="115px"><b>Message :</b></td>
                    <td width="400px"><textarea cols="30" rows="10" name="message"></textarea></td>
                  </tr>  
                  
                  <tr>
                    <td  align="left" valign="middle" width="115px"><input type="hidden" value="url" /></td>
                    <td width="400px"><input type="submit" value="Send Email" /><input type="reset" value="Reset" /></td>
                  </tr> 
                  
                  </table>     
  
</form>
<?php
}
?>
 
Still being a bit stupid, all I did was paste in the php parts from my email form into the html page, which made all the entry fields appear but above that is all the validation code, which now displays for everyone to see, how do I implement that?
 
Still being a bit stupid, all I did was paste in the php parts from my email form into the html page, which made all the entry fields appear but above that is all the validation code, which now displays for everyone to see, how do I implement that?

Not completely sure what you mean, but if you're using his code / something similar, what you need to do, is put the PHP code in a separate file named contact.php.

That's what this is for
Code:
<form action="contact.php" method="post">

Forgive me if this isn't what you needed :p
 
99.99% of hosting outfits, do not parse .html files through the PHP compiler. So your page would have to be renamed xxxxxx(whatever).php

Or you can use .htaccess to force the application type to php, but that wont work unless you have the right overrides, and it assumes apache+mod_php.
 
Back
Top Bottom