28th November 2014                                                                                                                                                        
Home / Webmaster News / Uber Contact Form Building Skills
by Joe Burnett
I’ve learned about blogs and websites and found that all successful ones have a simple way to contact the owner, creator, programmer, or writer. Doesn’t that mean that you need to...

Uber Contact Form Building Skills

by Joe Burnett

I’ve learned about blogs and websites and found that all successful ones have a simple way to contact the owner, creator, programmer, or writer. Doesn’t that mean that you need to start a contact page too? When I first started programming I did know all of the rules and functions, but I didn’t understand how to pull it all together and make a nice tasty script. That is exactly where almost everyone goes wrong!

            The first step in creating a contact form is the actual form. The form is of course going to be all html. Before you start you need to open the form tag and then close the form tag.

<form action=”mail.php” method=”POST”>

</form>

Alright, simple but I’ll go over it. When you open a form tag it can contain different attributes that describe the form and instruct it what to do. We added two attributes. Our two attributes are action and method. Action: The page the form will send the information to. Method: The type of process the form uses to send information to the action page. Either POST or GET. GET shows up in the url while POST doesn’t show up the url. Last we added the closing tag of the form. It is basic and contains no attributes.

Not done yet, we still need to provide the input fields which will allow the user to insert information such as name, email, website, message, etc. With the name input field what do you think the html tag name will be? Input! I’m going to build a form with the options to put a name, email, and message; perfect for the average contact form!

<form action=”mail.php” method=”POST”>

Name: <input type=”text” name=”name”> </br>

Email: <input type=”text” name=”email”> </br>

Message: <textarea cols=”45” rows=”3” name=”message”></textarea> </br>

</form>

Looks like a lot, so I’ll go easy. Alright, I color-coded the html for you so you can understand this without any confusion. Seriously. Yellow is what we already had down (The form tag). Red are the input tags I added. Purple is the huge textarea box I added for the message. Last Green is the basic br tag that forces the html page to move to the next line before outputting anything else.

The first input tag is going to be the name text box. Before the actual input tag is the text, “Name:”; Name: gets outputted before the text box.  After that we have some basic attributes inside the input tag. These attributes are type and name. Type: This is the type of user input data; it can be a text box, check box, radio box, file browse, and more. Name: Identifies the data that the user gave. Both name and email text boxes have the same type, but different names.

I thought we were doing input tags not textarea tags. A textarea tag is a special type of input. It can be called a text box. What’s the difference? A text box contains rows of available input data instead of one basic line. The text area adds a scroll bar to the edge of the text box for more user control.

The message again is a textarea text box. Its attributes are cols otherwise known as columns, rows, and name. Cols: exact amount of characters that can fit in the text boxes width. We gave columns a value of 45, rows a value of 3, and name a value of message. Hurray we are complete with the entire html form. Now let’s get down and dirty to work on some PHP code.

Before you do this I’d check to make sure your web host supports PHP. Some web hosts don’t allow any of their web sites to use PHP. After you check to see if you have PHP check and see if you have a good supply of SMTP. SMTP: Simple Mail Transfer Protocol This will send emails to you alerting someone has contacted you. Ready to begin?

<?php

$Name = $_POST[‘name’];

$Email = $_POST[‘email’];

$Message = $_POST[‘message’];

?>

Code, Code, Code you’ll see a lot of it. I hope this registers your brain. Remember our action attribute in the form tag? This PHP page, send.php is where you will add this code. If you haven’t learned any PHP <?php and ?> are the opening and closing tags. I hope you remember the name attribute in each of our input values name, email, and message. Here we are creating shorter PHP variables to hold the information the user gave us. If it doesn’t register in your head just bare with us.

<?php

If(isset($_POST[‘name’]) && isset($_POST[‘email’]) && isset($_POST[‘message’]))

{

$Name = $_POST[‘name’];

$Email = $_POST[‘email’];

$Message = $_POST[‘message’];

}

?>

I added an if statement. The if statement involves using the PHP function isset() and PHP’s && sign. The isset() function is pretty simple it does what it says. Isset() tells me and you if something exists. The && is just a way of telling PHP and. So in English our if statement really says, “if name and email and message exist then do this below.” Neat, huh?

<?php

If(isset($_POST[‘name’]) && isset($_POST[‘email’]) && isset($_POST[‘message’]))

{

$Name = $_POST[‘name’];

$Email = $_POST[‘email’];

$Message = $_POST[‘message’];

Mail(“[email protected]”,”Contact Form Submission”,”Name: $Name Email: $Email Message: $Message”,”From: Your Name Or Email”);

}

?>

Finally we are done! Your PHP script will work successfully! But what did I add? To alert you that somebody contacted you through your contact form we need to email you. One way to email you would be to use the PHP mail function. The PHP mail function has four availabilities for you to add data. The first is your email so replace [email protected] with your actual email ie: [email protected] Next is the subject. The current subject is Contact Form Submission. After that is the message which will tell you everything you need to know about the person trying to contact you. Last is who it’s from. Just put your email or your name.

What happens next? He clicks submit and bang a blank white page shows up. What happened? Was it a success? When will they contact me back? Now let’s do something that will help the user understand what happened. Let’s make PHP say something if it works, and say something bad if it fails.

<?php

If(isset($_POST[‘name’]) && isset($_POST[‘email’]) && isset($_POST[‘message’]))

{

$Name = $_POST[‘name’];

$Email = $_POST[‘email’];

$Message = $_POST[‘message’];

If(Mail(“[email protected]”,”Contact Form Submission”,”Name: $Name Email: $Email Message: $Message”,”From: Your Name Or Email”))

{

Echo “Your message has been sent I will respond within twenty four hours.”;

}

}

Else

{

Die(“Error! You missed one of the required fields. Try again.”);

}

?>

Now with that programmed PHP will say, “Error! You missed one of the required fields. Try again.” Only if the mail function was a complete fail, or the user didn’t fill in one of the required fields. If PHP did have success sending the e-mail, PHP will say, “Your message has been sent. I will respond within twenty four hours.” Good luck!

Q: What if I don’t have PHP or SMTP. A: You can switch web hosts that allow both, or just go to another web host, probably free and build a random site. After that, create the PHP page. Once the PHP page is complete, change your html form’s action attribute to point to that exact page.

Web Programming 101 is my blog all about web design and web development. I can teach you anything and will help you enjoy learning. I hope you liked my article, and I would love to connect with you on Twitter @WebProgramming1

  • aa aa

    One of many initial items you can do will be obtain a secure couple of good quality. That has been certainly one of my own, personal initial blunders; I might attention a lot more concerning the expense of compared to the design of which. The following point, some Tory Burch Ankle Suede Boots Red individuals set several ftrkuhjnvp apply about boot styles to produce these water-proof and also these kinds of, which is yet another thing which can be done to aid these previous slightly more time. My partner and i retain my own shoes or boots clear coming from weighty off-road and also mud at the same time. Several mud may be detrimental to shoes or boots, merely as they can be regarding autos. In order that will be yet another thing take into consideration in the event you both check out or perhaps stay around a spot together with mud. When you wind up acquiring mud on your own Tory Burch Belen Black Bootie, An excellent opportunity which you rinse the shoes or boots away from together with clear h2o and also permit these dried up appropriately.
    I permit my own shoes or boots dry inside the oxygen as opposed to the clothing dryer. I sensed in which Tory Burch Boho Black Suede Shearling Buckle Boots usually do not fit in the clothing dryer; I considered which they would certainly injury the particular clothing dryer. My partner and i don’t possess resistant in which blow drying shoes or boots inside the clothing dryer as opposed to oxygen dried up is way better for your shoes or boots, yet it could be any contributor to be able to exactly why my own shoes or boots have got held up more time as compared to other folks. Once you rinse the shoes or boots, it really is excellent to have in the shoes or boots along with exterior; and also bear in mind, they are going to acquire unclean once more nonetheless thus will not cause them to become pristine. Merely have the huge clumps regarding substance away from these and also work several h2o inside the inside of and also they should be ready to go regarding one more small bit.

Why RINF is different... And why you need to watch this...

RINF not only delivers the info you're not supposed to know, but also provides 100% free solution based videos and articles designed to help you to :

  • Improve your overall health
  • Get more financial independence
  • Stay informed & ahead of the curve
  • Become less dependent on corporations