Creating a feedback form - css markup. Don't forget about social networks
Hello dear readers, today I want to tell you about how I create forms to obtain user contact information.
Today, , is part of the landing page structure. After all, this is one of the ways to accept an order or send a catalog of your products, having previously received the visitor’s e-mail.
Creating a feedback form - html markup
I usually need three fields, and in most cases, I use this markup to create a contact form:
Try opening it in your browser this code and look what you get, depending on what Internet browser you use, it should look something like this:
If you have any questions about the markup, feel free to ask them in the comments, I will try to answer in detail, and I will not describe each element in the article so as not to increase its size. In addition, the elements are quite simple.
Creating a feedback form - css markup
Let's style our form and make it readable:
/* Form styles */ #application ( width: 475px; margin: 0 auto; ) /* Input field styles */ #applicationName, #applicationEmail, #applicationTelephone ( width: 100%; height: 73px; background: none; margin -top: 25px; border: 1px solid #fff; border-radius: 40px; text-align: center; color: #fff; font-size: 24px; ) /*Styles of fields when clicking on them*/ #applicationName:focus , #applicationEmail:focus, #applicationTelephone:focus ( border: 1px solid #30ad64; ) /*Styles of text displayed in placeholder*/ ::-webkit-input-placeholder ( color: #efefef; font-family: "PT Sans ", sans-serif; text-shadow: 0 1px 1px rgba(0, 0, 0, .3); ) ::-moz-placeholder ( color: #fff; font-family: "PT Sans", sans-serif ; text-shadow: 0 1px 1px rgba(0, 0, 0, .3); ) /* Firefox 19+ */ :-moz-placeholder ( color: #fff; font-family: "PT Sans", sans- serif; text-shadow: 0 1px 1px rgba(0, 0, 0, .3); ) /* Firefox 18- */ :-ms-input-placeholder ( color: #fff; font-family: "PT Sans" , sans-serif; text-shadow: 0 1px 1px rgba(0, 0, 0, .3); ) ::placeholder ( color: #fff; text-shadow: 0 1px 1px rgba(0, 0, 0, .3); ) /*Button styles*/ .applicationButton ( margin-top: 25px; background: #30ad64 ; border: none; width: 100%; height: 73px; border-radius: 40px; color: #fff; font-size: 24px; text-transform: uppercase; font-family: "PT Sans", sans-serif; cursor: pointer; ) .applicationButton:hover ( background: #d68c18; )
If you want the button color to change smoothly, add the following line to .applicationButton and .applicationButton:hover:
Transition: .6s;
Where.6s is the animation time in milliseconds.
Now our form has acquired beautiful view, now it looks like this:
Creating a feedback form - php markup
Now we need to create the application.php file. It will receive the entered parameters from the form and send them to us by email.
Its structure is like a regular one html file, this could be a page on which you write “Thank you, your application has been accepted. After processing the application, our managers will contact you"
That is, when the user clicks the button, he will be redirected to the application.php page. This is a full page and you should style it accordingly.
"; $msg .= "
Message from the site
\r\n"; $msg .= "From whom:".$username."
\r\n"; $msg .= "Mail:".$usermail."
\r\n"; $msg .= "Website:".$usertel."
\r\n"; $msg .= ""; // sending a message if(@mail($sendto, $subject, $msg, $headers)) ( echo "Let's explain the code a little:
$sendto = " [email protected]"; // mail to which the letter will be sent $username = $_POST["name"]; // save the data received from the field with the name into a variable $usertel = $_POST["telephone"]; // save the data into a variable received from the field with a phone number $usermail = $_POST["email"]; // save the data received from the field with an email address into a variable
Here, I think, it’s clear.
Now let's create the header of the letter.
$subject = "New message"; $headers = "From: " . strip_tags($usermail) . "\r\n"; $headers .= "Reply-To: ". strip_tags($usermail) . "\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html;charset=utf-8 \r\n";
Line $subject = "New message";— is responsible for the subject of the letter, can write there: “Application from the site” or whatever suits you best.
I propose to make sure that the letter arrives from the address specified in the input type="email" field. That is, from the one from which the user entered when filling out the form. To do this, we write the following lines:
$headers = "From: " . strip_tags($usermail) . "\r\n";
That is, we will substitute data from the $usermail variable, where the information from the field responsible for entering the email address is stored.
Now let's set appearance letters. You can design it however you like, but I suggest the following structure:
$msg = "
"; $msg .= "Message from the site
\r\n"; $msg .= "From whom:".$username."
\r\n"; $msg .= "Mail:".$usermail."
\r\n"; $msg .= "Telephone:".$usertel."
\r\n"; $msg .= "";The first line sets the letter font. Second, we display a message, for example: “Request from the form feedback on the first screen." The third, fourth and fifth lines transmit data from the form. Each on a new line.
Now you need to send a letter using the mail function and determine what will happen if the letter is sent successfully and not successfully:
If(@mail($sendto, $subject, $msg, $headers)) ( echo "
I made it so that in any of the cases a picture with the corresponding text will be displayed. You can display a full page instead of a picture. Just write the code instead of the picture.
A few seconds later, after the image is displayed, I redirect (automatic redirection) to the main page. This can be done by entering next line between head tags;
That is, after 4 seconds the user will automatically be returned to the main page!
I'm not an expert in PHP - it's a back-end programming language; I've been drawn to learning front-end all my life. So don't judge harshly. Yes, here you can make checks for filling out contact forms and so on, but this was always enough for me, so if anyone has a suggestion on how to improve this code, please write in the comments or by email, I will correct the lesson, thank you!
By the way, if you need a feedback form without reloading the page, then you can read about how to install it in
Maybe some people don’t understand the material very well, but if you repeat my steps exactly, it will definitely work for you contact form. If you have any questions, write in the comments, I’ll try to answer! See you on the blog!
P.s. Since I began to very often receive questions about why the form does not work and emails do not arrive, I decided to describe several of the most popular reasons why this may happen:
- You are testing the form not on the server.
- Testing the form for demons paid hosting.
- You test the form on paid hosting, but during the free trial period.
In these cases, letters will not be sent to your email.
If you are too lazy to figure it out and make the form yourself, then I recommend paying attention to.
23/07/2014 12/07/2018
dimadv7