Feedback form for the site which I'll show you is based on the use of Ajax technology. But do not worry, you do not need to know this, everything is ready, you just need to install this form and customize it for yourself!
Guys - the script is outdated for a long time. Someone works, someone does not. And I'm too lazy to figure it out and even more so to update. Therefore, test at your own discretion.
Php feedback form with sending to mail
This feedback form to the site very functional in itself, several plugins are connected to it that create an attractive appearance and check the validity (read correctness) of the data you entered. These plugins work on the great and the mighty! And they are called like this:
1. JQTransform- a plugin that allows you to make our feedback form beautiful!
2. formValidator- and this plugin checks the contact form for the correctness of the information entered and in which case it displays tooltips!
For the full-fledged work of this form, the PHPMailer class will be used. Considered one of the best!
A note for the smartest:
The feedback form for the site can be made in HTML! But it will only start working with PHP! And nothing else!
This is me for those who are looking for a feedback form only in HTML. You will do it, but it will not work!
Therefore, yours must support PHP, and for this contact form, PHP must be at least version 5. I hope I'm making it clear? Moreover, now, any normal hosting supports these conditions!
I dug up this feedback form on the website www.tutorialzine.com, the link leads directly to the original page, i.e. site of the author of this form!
Everything is in English, so Sasha and I had to tinker a little to Russify this contact form and the plugins themselves that are connected to it.
To be honest, we spent two days with this "form", as various jambs began to emerge, and I did not want to upload the unfinished feedback form, all the more so beautiful! So if you are a fan of doing everything yourself, and the thought will fit into your brightest head - to Russify this form yourself, I will give a couple of tips, since you will not be limited to simply translating phrases:
1. This feedback form is tailored for the bourgeoisie, and downloaded from there, so it will send you instead of normal Russian symbols - krakozyably. Understand the encoding. Anyway, all "seals" will be associated with this!
2. The validation script initially does not understand our letters, so they will need to be written there!
3. Even after these actions, if you specify the subject of the letter in Russian, the letter comes with a subject - No subject (I hope I wrote it correctly), this is treated if you specify the encoding in the PHPMailer class file.
4. In the original form, the text in the input fields was pressed to the bottom, not in the middle. This is a JQTransform plugin glitch.
Well, he seems to have written everything down and warned me. Let's go further!
Hello, friends! In this tutorial we will talk about creating a feedback form, or as they say among the people "Contact form".
Today we will analyze with you how you can create in a few minutes easy, beautiful and functional a feedback form using my favorite plugin Contact Form 7 .
I will try to explain in as much detail as possible all the stages of installing the contact form, and in this regard, the lesson will turn out to be quite long 🙂
Creating a contact form in WordPress
At the very beginning, I want to note that the Contact Form 7 plugin is Russified, and you will not have any problems with it. As proof of my words, the fact that this plugin was downloaded can be MORE THAN 25 MILLION TIMES !!!
And so, let's get started. To create a feedback form you need to do the following:
1. Install and activate the Contact Form 7 plugin. How to install plugins you can.
2. After activation, go to Contact Form 7 -> Forms.
3. In the window that opens copy the line with an embed code.
4. Paste the copied code on the page where we want to add a feedback form. After you have inserted the code, do not forget to save the changes by clicking the button "Refresh".
Here is such result adding a contact form to get:
Ready! You installed working form feedback to your site!
As you can see, in total in a few minutes you can easily install a feedback form on the site. You can put an end to this, but for those who are not satisfied with the standard form and who want create completely new contact form with other fields and possibilities - recommend read the lesson to the end.
In order to create a new form, you first need to determine what fields we need in it. In this tutorial, as an example, we will create a simple call back order form.
To do this, we need the following fields to be filled in the form:
- Name (Required field)
- Surname
- Phone (Required field)
- A field with a choice of a convenient time for a call
After we have decided on the fields, we proceed to creating the form:
1. Go to Contact Form 7 -> Add New.
2. In the window that opens, press the button "Add new"... If necessary, select a language from the drop-down list below. By the default language will be Russian.
3. After clicking the button, you will be taken to the page on which the form editor.
At the very top of the page is the field in which we write title new form... V Form template we see standard form fields that are created by default.
Below we see the settings of the letter that comes to your mail after someone has sent an order from the form on the site. In these settings, for example, you can change or add an e-mail, which will receive requests from the form on your site. V letter template the information that will be displayed inside the letter is configured.
4. After we have superficially familiarized ourselves with the structure of the editor, we proceed to creating our new form. For this we need DELETE from the form template all lines except for the button "Send", and in the email template delete all completely . After deleting, you should get something like this:
5. Now we need to create new fields: Name(required), Surname, Telephone(required), Convenient call time.
We start by creating a field to enter a name, which should be required. To do this, press the button "Generate Tag" and choose Text field.
In the settings of the new field, put a check mark, which is only necessary if the field should be required. Next, copy the generated code into the form template on the right, and copy the following code into the email template. See the image below for comments and arrows for better understanding.
6. After we have added a field for entering a name, click "Generate Tag" -> Text Field and by analogy create a field Surname and Telephone by copying and pasting the code into the form template and the letter template. The only difference is that for the field Surname you do not need to check the box for mandatory filling .
After adding the First Name, Last Name and Phone fields, the form editor will look like this:
7. Now we create the field Convenient call time. To do this, click "Generate Tag" and choose "Drop-down menu".
In field Choice we write in a line according to one option, in our case this time is from 8-00 to 18-00 at intervals of two hours. After filling out, copy the corresponding lines of code into the form template and the letter template.
As a result, you should get something like this:
9. Copy the form code and paste it on the page where you need the form... If you did everything correctly, you should get the following form for ordering a call back:
After the user makes a callback order from your site, a letter will be sent to your mail with the following content:
READY! Here we have created with you callback order form from scratch.
I agree that for some, everything may seem very difficult and scary, but this feeling will only last until the first creation of a contact form from scratch 😉
In most cases, a standard feedback form, which is created by the plugin by default immediately after its installation and activation, is sufficient.
I hope this tutorial was useful to you, and you figured out the Contact Form 7 plugin.
If you have any questions during the creation of the form or something will not work - write and ask questions in the comments.
And remember that feedback form on the site - a required attribute on the contact page.
Hello, friends! In this lesson we will talk about creating a feedback form, or as the people say "contact form". Today we will discuss with you how you can create an easy, beautiful and functional feedback form in a few minutes using my favorite Contact Form 7 plugin. I will try to explain in as much detail as possible all the stages of installing a contact form, and in this regard, the lesson will turn out to be quite long :) Creating a contact form in WordPress At the very beginning, I want to note that the Contact Form 7 plugin is Russified, and you will not have any problems with it. As proof of my words, the fact that this plugin ...
Overview
Vote for the lesson
100
Grade
Outcome: Dear Readers! Do not be lazy to vote and leave a comment. This way I can understand the usefulness of the lessons and articles, and improve their quality in the future. Thank you in advance!
Create a feedback form
Creating a feedback form on the site
In the process of website promotion, along with the study of statistics of visits, information about the site from the visitors themselves is of particular importance. One of the easiest ways to obtain such information is to post a page on the site with feedback form... The visitor leaves a message, and it will come to your email address or whatever you specify. At the same time, the visitor does not need to use his mail program, he does not even need to have his own e-mail.
The simplest example of such a form is shown in Fig. 1. (This is a perfectly working sample, and you can use it to send me a thank you letter.)
Fig. 1. Simple contact form
To post such a feedback form on the site, just basic information about HTML and the ability to operate with two commands is enough - Copy and Insert. Let's consider the sequence of actions for creating a feedback form (Fig. 1) on the HTML page of the site.
1. Check that your hosting plan (the office where your site is hosted) supports PHP. If not, then you will most likely have to pay extra to switch to another tariff that supports this same PHP. You do not need to search for the meaning of this abbreviation, since you will not need knowledge of PHP.
2. Let's select the page on which we want to place the feedback form and insert the following code in the right place:As you can see, the whole form is created with the tag with attributes action = mail.php(an indication of the page of the site where the script for processing the entered data is located) and method = post(method of sending data to the server). The individual lines are created by the tag with quite understandable attributes. The location of individual form elements, text, fonts, etc. can be changed in accordance with the design of your site. In the tag sets the size of the area for entering the text of the message: the number of rows and columns (rows = "3" cols = "25").
3. Let's create a new page mail.php, similar to normal HTML, only with the .php extension. The complete page code is shown in Figure 2:
if (isset ($ _ POST ["name"])) ($ name = $ _POST ["name"];)
if (isset ($ _ POST ["email"])) ($ email = $ _POST ["email"];)
if (isset ($ _ POST ["mess"])) ($ mess = $ _POST ["mess"];)
$ to = "pupkin@rambler.ru"; / * Enter your email address * /
$ headers = "Content-type: text / plain; charset = utf-8";
$ subject = "Post from your site";
$ message = "Sender's name: $ name \ nEmail address: $ email \ nMessage: $ mess";
$ send = mail ($ to, $ subject, $ message, $ headers);
if ($ send == "true")
{
echo " Thanks for sending your message!
";
echo " Click, to return to the main page ";
}
else
{
echo "
Error. Message not sent!";
}
?>
Fig. 2. Feedback form processing page code
Links are highlighted in red, which you need to pay attention to:
- pupkin@rambler.ru - replace the address of Pupkin with your mail address, where messages from site visitors, as well as from tireless spammers, will be sent. By the way, to protect against them, the so-called captcha (eng. CAPTCHA- Completely Automated Public Turing test to tell Computers and Humans Apart - a fully automated public Turing test for distinguishing computers and people). Usually these are highly distorted numbers and letters that are asked to enter before sending a message. We will talk about captcha in one of the following articles.
If you want to send letters to several addresses, just list them separated by commas. - a href = index.html - the address of the main (home) page of the site.
Created page mail.php must be placed in the same directory of the site (directory, folder) where the page with the feedback form is located.
Check the functionality of the feedback form. If everything is done carefully, then after filling out the form and clicking send a message the following text should appear: " Thanks for sending your message. to return to the main page". After that, you will find in your mailbox (or a friend that you indicated when creating the feedback form) your own message to your beloved.
Comment: on some hosting, the new (just installed on the site) feedback form does not start working immediately, and the first letters do not reach at all or arrive with a delay of 1-2 days. Probably, there is a "grinding in gears", and then everything works fine. In addition, some hosting sites do not receive letters to certain addresses, for example, I had problems with my mailbox on Rambler and Mail.ru. To solve these problems, contact your hoster - they usually help.
Sometimes, when using the described feedback form, problems with encoding arise. If, instead of the native Cyrillic alphabet, the text in the received letter consists of "krakozyablov" or empty squares, then you have to manually select the encoding, which is of course inconvenient. To prevent this from happening, check that your contact form page is encoded. charset = utf-8... If you are using the program Adobe dreamweaver, then for this you need to select the menu section Edit - Page Properties - Encoding.
For more details on the problem with the encoding of site files, see the article Encoding problems in the feedback form.
In the described example, for simplicity, the message about sending a letter is displayed on a blank page. Of course, you can place it on any page of your site so that the visitor can use the navigation (menu) to select further actions. To do this, place the PHP code (which is located from<? php before ?> ) to the desired place on the menu page and change its name to mail.php.
In addition to placing the feedback form itself, it is advisable to check the correctness of filling in its fields by the visitor. This must be done so that you do not receive empty letters and your mailbox is not clogged with junk sent by pranksters who just like to press a button. send a message... Methods for checking the completion of the feedback form and protecting against spam are described in the articles "
One of the most common tasks in practice is the implementation of the feedback form. You write its HTML code, decorate it in CSS, create a PHP script that would process the data received from the user and send it to our mail, write a JS script that would check the form for the adequacy of the input data, protect our brainchild from spam, so that our the mailbox did not collapse from bot attacks.
All of the above points will be considered in our review and commented in detail.
So, let's start creating a feedback form:
Html
First of all, we write HTML code, it sets the fields that the user will fill in. They will be issued in the future. The form code looks like this:
< form method= "post" action= "mail.php" > < div class = "left" > < label for = "name" >Name: label> < input maxlength= "30" type= "text" name= "name" /> < label for = "phone" >Telephone: label> < input maxlength= "30" type= "text" name= "phone" /> < label for = "mail" >E-mail: label> < input maxlength= "30" type= "text" name= "mail" /> div> < div class = "right" > < label for = "message" >Message: label> < textarea rows= "7" cols= "50" name= "message" > textarea> < input type= "submit" value= "send" /> div> form>
And visually it now looks like this:
I agree, so far everything is ugly and nothing is clear, but we have just begun.
Consider the above code in detail:
< form method= "post" action= "mail.php" > … form>
in order to create a form, you must use the form tag. It is he who determines the beginning and end of the form for the code interpreter. It, like any tag, has a whole set of attributes, but there are only two required for the form to work, these are method (the method for sending a request to the server, for forms they use post as standard) and action (specifies the path to the file-handler of the form, exactly in this file will contain a script in PHP, which will then send the values ​​entered by the user to our mail, in our case we see that this file is called mail.php and it lies in the same directory of the site as the page we are considering).< input maxlength= "30" type= "text" name= "name" />
Next, we have inputs. These are the actual form fields in which users will enter the information we need (type = "text" means that it will be text). The maxlength attribute specifies how many characters a user can enter into a given form field. The most important attribute is name - it specifies the name of a particular field. It is by these names that in the future the PHP script will process the information entering it. If desired, you can also set the placeholder attribute, which displays text inside the field that disappears when the cursor is placed inside it. One of the problems with the placeholder is that it is not supported by some older browsers.< label for = "name" >Name: label>
Used in case we have abandoned placeholders. The usual signature of a field, the for attribute tells which specific field this signature belongs to. The value specifies the name of the field of interest.< textarea rows= "7" cols= "50" name= "message" > textarea>
Just like the input is intended for the user to enter information, only this time the field is sharpened for long messages. Rows indicates the size of the field in rows, cols in characters. In general, they set the height and width of our box.< input type= "submit" value= "send" />
Type = "submit" tells us that this is a button for submitting a form, and value sets the text that will be inside this button.< div class = "right" > div>
used only for further visual design of the form.
CSS
In order for our feedback form to look presentable, you need to arrange it. To get the following result:
We used the given code:
form (background: # f4f5f7; padding: 20px;) form. left, form. right (display: inline-block; vertical-align: top; width: 458px;) form. right (padding- left: 20px;) label (display: block; font- size: 18px; text- align: center; margin: 10px 0px 0px 0px;) input, textarea (border: 1px solid # 82858D; padding: 10px; font- size: 16px; width: 436px;) textarea (height: 98px; margin- bottom: 32px;) input [type = "submit"] (width: 200px; float: right; border: none; background: # 595B5F; color: #fff; text- transform: uppercase;)
I do not see the point in describing the CSS in detail, I will draw your attention only to the key points:
- You shouldn't write a design for every tag in the form. Try to build your selectors so that you can style all the elements you need with a couple of lines of code.
- Do not use extra tags by type for line breaks and indentation < br>, < p> and so on, CSS does a great job with the display: block property and margin with padding. More on why not to use < br> in the layout you can generally read the tag br in the article, but is it really needed? ...
- Don't use tabular form layouts. This is contrary to the semantics of this tag, and search engines love semantic code. In order to form the visual structure of the document, we need only the div tags, and the display: inline-block (arranges blocks in a row) and vertical-align: top (prevents them from scattering across the screen) properties set by them in CSS, set them the required height and voila, nothing more and everything is located the way we need it.
For those who want to save their time on website design, I can advise you to use CSS frameworks when creating websites, especially self-written ones. My choice for this plan is Twitter Bootstrap. You can watch a lesson on designing forms using it.
PHP
Well, now it's time to make our form workable.
We go to our site root directory and create a mail.php file there, to which we previously indicated the path in the action attribute of the form tag.
Ultimately, his code will look like this:
His number is ". $ Phone."
His mail: ". $ Mail. "
His message: "... $ message,); echo "Your message has been sent successfully!
You will receive an answer shortly.
$ back "; exit; ) else (echo; exit;)?>
The discussion of the HTML and CSS portion of this document can be skipped. At its core, this is an ordinary page of the site, which you can design as you wish and need. Let's consider the most important part of it - the PHP script for processing the form:
$ back = "
\ "javascript: history.back () \"> Go back
" ;With this line, we create a link to return to the previous page. Since we do not know in advance from which page the user will get to this one, this is done using a small JS function. In the future, we will simply refer to this variable to display it in the places we need.
if (! empty ($ _POST ["name"]) and! empty ($ _POST ["phone"]) and! empty ($ _POST ["mail"]) and! empty ($ _POST ["message"])) ( // inner part of the handler) else (echo "Please fill in all fields to send your message! $ Back"; exit; )
Here we attach the check of the form for the fullness of the fields. As you may have guessed, in the $ _POST ["name"] part, in quotes, we write the value of the name attribute of our inputs.
If all the fields are filled in, then the script will start processing the data in its internal part, if at least one field was not filled in, then a message will be displayed on the user's screen with a request to fill in all the fields of the form echo "To send a message, fill in all the fields! $ Back" and a link to return to the previous page that we created on the very first line.
Then we insert into the inner part of the form handler:
$ name = trim (strip_tags ($ _POST ["name"])); $ phone = trim (strip_tags ($ _POST ["phone"])); $ mail = trim (strip_tags ($ _POST ["mail"])); $ message = trim (strip_tags ($ _POST ["message"]));
Thus, we have cleared the user input from html tags and extra spaces. This allows us to protect ourselves from receiving malicious code in messages sent to us.
The checks can be complicated, but this is already at your request. We have already installed the minimum protection on the server side. Further we will do on the client side using JS.
I do not recommend completely abandoning form protection on the server side in favor of JS, because, although it is extremely rare, there are unique ones with JS disabled in the browser.
After cleaning the tags, add sending a message:
mail ( "mail_for_receiving_messages@gmail.com",
"Letter from your_site_address", "I wrote to you:" $ name. "
His number is ". $ Phone."
His mail: ". $ Mail. "
His message: "... $ message, "Content-type: text / html; charset = windows-1251")
;
It is this line that is engaged in the formation and sending of a message to us. It is filled in as follows:
- "mail_for_receiving_messages@gmail.com" - insert your mail here between the quotes
- "Letter from your_site_address" is the subject of the message that will arrive in the mail. You can write anything here.
- "I wrote to you:". $ Name. " < br /> His number is ". $ Phone." < br /> His mail: ". $ Mail." < br /> Its message: ". $ Message - we form the text of the message itself. $ Name - we insert the information filled in by the user through referring to the fields from the previous step, in quotes we describe what this field means, with the tag < br /> we make a line break so that the message as a whole is readable.
- Content-type: text / html; charset = windows-1251 - at the end there is an explicit indication of the data type transmitted in the message and its encoding.
IMPORTANT!
The encoding specified in the "head" of the document ( < meta http- equiv= "Content-Type" content= "text / html; charset = windows-1251" /> ), the encoding from the message Content-type: text / html; charset = windows-1251 and, in general, the encoding of the PHP file must match, otherwise, messages received by mail will display "krakozyabry" instead of Russian or English letters.
Many do not explicitly indicate the encoding of the message being sent, but on some mail clients, this may cause problems in the future (unreadable letters come to the mail), so I recommend specifying it all the same.
Checking the form for the adequacy of the entered data
So that users do not miss the fields by inattention and fill in everything correctly, it is worth checking the entered data.
This can be done in both PHP on the server side and JS on the client side. I use the second option, because this way a person can immediately find out what he did wrong and correct the mistake without making additional transitions through the pages.
Insert the script code in the same file where the HTML part of the form is located. For our case, it will look like this:
< script>function checkForm (form) (var name = form. name. value; var n = name. match (/ ^ [A- Za- zA- Ya- z] * [A- Za- zA- Ya- z] + $ / ); if (! n) (alert ( "The name was entered incorrectly, please correct the mistake."); return false; ) var phone = form. phone. value; var p = phone. match (/ ^ [0 - 9 +] [0 - 9 -] * [0 - 9 -] + $ /); if (! p) (alert ( "Phone entered incorrectly"); return false; ) var mail = form. mail. value; var m = mail. match (/ ^ [A- Za- z0- 9] [A- Za- z0- 9 \. _-] * [A- Za- z0- 9 _] * @ ([A- Za- z0- 9] + ([A- Za- z0- 9 -] * [A- Za- z0- 9] +) * \.) + [A- Za- z] + $ /); if (! m) (alert ( "E-mail entered incorrectly, please correct the error"); return false; ) return true; )
Well, now the usual parsing:
For, so that when you click on the submit button of the form, we have it checked we hang the launch of our script on the form tag:
< form method= "post" action= "mail.php" onSubmit= "return checkForm(this)" >
Now, point by point, we take the composition of the check:
![](https://i0.wp.com/vaden-pro.ru/sites/default/files/soobchenie-o-oshibke.png)
As you can see, such a mini check is written for each of our fields. I highlighted the check for one field in the screenshot with a red square, for other fields it has a similar structure and if there is a need to add a field or remove it, you can now easily do it.
Hi guys. Seryoga is in touch. I know that I have not written for a long time - business, business ... And now, to be honest, there is absolutely no time. And we will make the form not according to my lesson, but according to the lessons of my friend - Krotova Romana.
Create a feedback form for the site we will be consistent. Therefore, this article will be split into 3 lessons.
We'll just put it in HTML and create a PHP handler for sending emails. Everything will be consistent, from scratch to the result. So that you would understand everything and be able to embed the necessary fields on your own.
Roma will show you how to do Ajax loading. That is, send data from the form without reloading the page. Which, you see, is very convenient and modern.
Well, in the third (the lesson is being prepared - later there will be a link here), we will inline a validation check. Not by means of a browser, but with the help of special scripts.
Video 1. Creating a feedback form for the site.
Paying attention! For the form to work, you need your hosting to support PHP.
If you have any questions regarding unclear points in writing a form handler for sending letters - do not hesitate to ask them in the comments.
Code from the lesson on creating a feedback form
This is what ended up in the index.php file
I remind you what it contains simple feedback form... Without registration and other bells and whistles. In order not to burden you with unnecessary information.
Content of file submit.php:
This is where a basic check of the form is performed, so as not to send empty messages. If everything is "good" - the letter is sent. And there is a redirect to the notification page about the successful sending of the letter.
If (! Empty ($ _ POST ["name"]) AND! Empty ($ _ POST ["email"]) AND! Empty ($ _ POST ["message"])) ($ headers = "From: Roman Krotov." Reply-To: [email protected]"." X-Mailer: PHP / ". Phpversion (); $ theme =" New message from site "; $ letter =" Message details: "; $ letter. =" "; $ Letter. =" Name: ". $ _POST ["name"]; $ letter. = "Email:". $ _ POST ["email"]; $ letter. = "Phone:". $ _ POST ["phone"]; $ letter. = "Message:" . $ _ POST ["message"]; if (mail (" [email protected]", $ theme, $ letter, $ headers)) (header (" Location: /testform/thankyou.php ");) else (header (" Location: / testform ");)) else (header (" Location: / testform ");)
Well, I see no reason to post the notification page itself. There's the basic structure of an HTML document and just one line of text.