How do i get this contact form work?

  • MarcK
  • Born
  • Born
  • MarcK
  • Posts: 4

Post 3+ Months Ago

Sorry but i am new to this... how do i get this contact form to work? thx for your Help!!! Marc

HTML Code: [ Select ]
<!--==============================content================================-->
         <section id="content"><div class="ic"></div>
            <div class="main">
               <div class="content-padding-2">
                  <div class="container_12">
                     <div class="wrapper">
                        <article class="grid_8">
                           <div class="padding-grid-1">
                              <h3>Contact <strong>Form Management</strong></h3>
                              <form id="contact-form" enctype="multipart/form-data" method="post" >
                                 <fieldset>
                                    <label>
                                       <span class="name-input">Name:</span>
                                       <input name="name" value="" onBlur="if(this.value=='') this.value=''" onFocus="if(this.value =='' ) this.value=''" />
                                    </label>
                                    <label>
                                       <span class="name-input">Email:</span>
                                       <input name="name1" value="" onBlur="if(this.value=='') this.value=''" onFocus="if(this.value =='' ) this.value=''" />
                                    </label>
                                    <label>
                                       <span class="name-input">Message:</span>
                                       <textarea onBlur="if(this.value=='') this.value=''" onFocus="if(this.value =='' ) this.value=''"></textarea>
                                    </label>               
                                 </fieldset>
                                 <div class="link-form">
                                    <a class="link link-margin" href="#" onClick="document.getElementById('contact-form').reset()">Clear</a>
                                    <a class="link" href="#" onClick="document.getElementById('contact-form').submit()">Send</a>
                                 </div>
                                 <div class="clear"></div>     
                              </form>
  1. <!--==============================content================================-->
  2.          <section id="content"><div class="ic"></div>
  3.             <div class="main">
  4.                <div class="content-padding-2">
  5.                   <div class="container_12">
  6.                      <div class="wrapper">
  7.                         <article class="grid_8">
  8.                            <div class="padding-grid-1">
  9.                               <h3>Contact <strong>Form Management</strong></h3>
  10.                               <form id="contact-form" enctype="multipart/form-data" method="post" >
  11.                                  <fieldset>
  12.                                     <label>
  13.                                        <span class="name-input">Name:</span>
  14.                                        <input name="name" value="" onBlur="if(this.value=='') this.value=''" onFocus="if(this.value =='' ) this.value=''" />
  15.                                     </label>
  16.                                     <label>
  17.                                        <span class="name-input">Email:</span>
  18.                                        <input name="name1" value="" onBlur="if(this.value=='') this.value=''" onFocus="if(this.value =='' ) this.value=''" />
  19.                                     </label>
  20.                                     <label>
  21.                                        <span class="name-input">Message:</span>
  22.                                        <textarea onBlur="if(this.value=='') this.value=''" onFocus="if(this.value =='' ) this.value=''"></textarea>
  23.                                     </label>               
  24.                                  </fieldset>
  25.                                  <div class="link-form">
  26.                                     <a class="link link-margin" href="#" onClick="document.getElementById('contact-form').reset()">Clear</a>
  27.                                     <a class="link" href="#" onClick="document.getElementById('contact-form').submit()">Send</a>
  28.                                  </div>
  29.                                  <div class="clear"></div>     
  30.                               </form>
Moderator Remark: Please remember to use [code][/code] around any code in your post to make it more readable. Thank you!
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9090
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Hi Marc,

What you posted there is just the HTML for the frontend of your wesite. In other words its the HTML code to give you the look and feel for your website contact form. To actually get the contact form to do something, such as send you a message via e-mail, you need to also find some sort of contact script. I am not sure what sort of programming language you would want to use as it depends on your hosting environment, but there are all sorts of free PHP contact forms scripts out there that you could integrate with what you have.

Once you do have a script and have installed it, you would need to change line 10 in the code you post above:

HTML Code: [ Select ]
<form id="contact-form" enctype="multipart/form-data" method="post" >


To point to the contact script. For example, if your script is named contact.php then you might change the code to:

HTML Code: [ Select ]
<form id="contact-form" enctype="multipart/form-data" method="post" action="contact.php">
  • MarcK
  • Born
  • Born
  • MarcK
  • Posts: 4

Post 3+ Months Ago

Thx for the Info, so the code i put in can look like this?
do i put it in the directory of my site or on top of my contact.html?

Code: [ Select ]
<?php $to = "my mail address"; $subject = "Contact Us"; $email = $_REQUEST['email'] ; $message = $_REQUEST['message'] ; $headers = "From: $email"; $sent = mail($to, $subject, $message, $headers) ; if($sent) {print "Your mail was sent successfully"; } else {print "We encountered an error sending your mail"; } ?>
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9090
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

You would put that in its own file and name it something like contact.php. You then need to make sure the variables that the script is looking for, ie "email", "message" are located in your HTML code. For instance it looks like your textarea in your HTML code has no name or ID attribute on it. You would need to make sure to add that and call it message so that the PHP script can grab the variables. So in other words:

HTML Code: [ Select ]
<textarea onBlur="if(this.value=='') this.value=''" onFocus="if(this.value =='' ) this.value=''"></textarea>


Would need to become:

HTML Code: [ Select ]
<textarea name="message" id="message" onBlur="if(this.value=='') this.value=''" onFocus="if(this.value =='' ) this.value=''"></textarea>


For every variable that your script is looking for, you need to make sure that your text area and input elements are named accordingly in your HTML.

With your script, keep in mind that it is a very basic simple script that will allow you to learn how to integrate everything. By the looks of it I would not use that in a production setting as there is absolutely zero input validation going on there. What that means is that the way the script is currently written, someone with bad intentions could use that script to do bad things such as sending out tons of spam from your website. If you do not know how to write a PHP script that does validation, you might want to look around on the net for a more sophisticated PHP contact script that actually checks any input that is passed to the script to make sure someone isn't trying to pass along malicious values.
  • MarcK
  • Born
  • Born
  • MarcK
  • Posts: 4

Post 3+ Months Ago

I thought this was easier.. ;-)) so my php is to easy and i should get a validating one.. or better one, i never used a contact form before so this is complete new to me.. but thx anyway
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9090
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

No problem. There is nothing wrong with using that simple script just so you can play around to see if you can get it all to work. That would be a good learning experience for you to see if you can get your HTML and PHP script to work together. Just keep in mind that once you do get that figured out, you will want to get a PHP contact form script that performs validation, otherwise you will likely get spammers who start abusing your script.
  • MarcK
  • Born
  • Born
  • MarcK
  • Posts: 4

Post 3+ Months Ago

Found this php can you please help me once again, tell me what i should do in my php code and if i need anything changed in my HTML, thank you so much! Marc

Code: [ Select ]
<?php
$your_email = "Youremail(at)yoursite(dot)com"; #Enter your email
//Enter your email here
ini_set("sendmail_from", "user(at)yourdomain(dot)com");

$subject = "Your subject"; #Enter your subject

//Some main php variables
$name = '';
$email = '';
$message = '';

$errors = array();

//Submit button variable

$submit = (isset($_POST['submit'])) ? TRUE : FALSE;

//Check if submit was pressed

if($submit){
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$email_check = "/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i";
$headers = "From: $name <$your_email>";
//------------Validation---------------
if(!$name){

$errors[] = "Please enter your name!";

}
if($name){
//Stop header injection on the name field
if(preg_match('/.@/',$name){

$errors[] = "Please enter only valid characters in the name field!";
}

}
if(!$email){

$errors[] = "Please enter your email address!";

}
if($email){
if(!preg_match($email_check,$email){
$errors[] = "Please enter a valid email address!";

}

}else{

$body = "
You have a new message from your site/n/n/n
Name: /n/n $name /n/n
Email: /n/n
$email /n/n
Message: /n/n
$message
";

mail($your_email,$subject,$body,$headers,"-fYouremail(at)yoursite(dot)com");
echo "Thank you for your message!";

}

}

?>
  1. <?php
  2. $your_email = "Youremail(at)yoursite(dot)com"; #Enter your email
  3. //Enter your email here
  4. ini_set("sendmail_from", "user(at)yourdomain(dot)com");
  5. $subject = "Your subject"; #Enter your subject
  6. //Some main php variables
  7. $name = '';
  8. $email = '';
  9. $message = '';
  10. $errors = array();
  11. //Submit button variable
  12. $submit = (isset($_POST['submit'])) ? TRUE : FALSE;
  13. //Check if submit was pressed
  14. if($submit){
  15. $name = $_POST['name'];
  16. $email = $_POST['email'];
  17. $message = $_POST['message'];
  18. $email_check = "/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i";
  19. $headers = "From: $name <$your_email>";
  20. //------------Validation---------------
  21. if(!$name){
  22. $errors[] = "Please enter your name!";
  23. }
  24. if($name){
  25. //Stop header injection on the name field
  26. if(preg_match('/.@/',$name){
  27. $errors[] = "Please enter only valid characters in the name field!";
  28. }
  29. }
  30. if(!$email){
  31. $errors[] = "Please enter your email address!";
  32. }
  33. if($email){
  34. if(!preg_match($email_check,$email){
  35. $errors[] = "Please enter a valid email address!";
  36. }
  37. }else{
  38. $body = "
  39. You have a new message from your site/n/n/n
  40. Name: /n/n $name /n/n
  41. Email: /n/n
  42. $email /n/n
  43. Message: /n/n
  44. $message
  45. ";
  46. mail($your_email,$subject,$body,$headers,"-fYouremail(at)yoursite(dot)com");
  47. echo "Thank you for your message!";
  48. }
  49. }
  50. ?>
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9090
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

You basically just need to match up the variables its looking for in the PHP program and modify them in your HTML. In your PHP code it shows:

PHP Code: [ Select ]
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
  1. $name = $_POST['name'];
  2. $email = $_POST['email'];
  3. $message = $_POST['message'];


So it is looking for:

name
email
message

So in your HTML you need to name your input fields accordingly. It is also looking for a submit variable to be present:

PHP Code: [ Select ]
$submit = (isset($_POST['submit'])) ? TRUE : FALSE;


so make sure you name your submit button as "submit", or add a hidden input field named submit with a value of 1 in your HTML.

Post Information

  • Total Posts in this topic: 8 posts
  • Users browsing this forum: No registered users and 137 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.