Building a simple contact form with Angularjs and php. Solution to the problem: Sorry, there was an error on Instagram Configure the application for identification

It is very convenient to always know what specific version this or that assembly of the project is. This is usually done by entering a version number consisting of several digits. I am a proponent of a 4-digit structure like:

Together, this forms the full version naming (Major.Minor.Pathch.Build):

Some people use a unique build as their build. numerical value which increases every time, for example, with a night build. I believe that there is no point in this - it is much more convenient to bind this number to a revision in the repository. I use Subversion and CMake, so I will demonstrate how you can automate the posting of a build version with these tools.

First, you need to add a header file to the project (for example, version.h):

#include #include namespace Version (const std :: string & AsText (); boost :: uint64_t AsNumber ();)

Here is a simple interface through which you can get the number from the program full version in text form or as a unique integer identifier.

Now I will give the content of version.cpp:

#include #include "../version.h" namespace (const boost :: uint8_t MAJOR = 4; const boost :: uint16_t MINOR = 6; const boost :: uint16_t PATCH = 12; const boost :: uint32_t BUILD = 589; // This value will be changed automatically) const std :: string & Version :: AsText () (static const std :: string text = boost :: str (boost :: format ("% 1%.% 2%.% 3%.% 4%") % static_cast< unsigned >(MAJOR)% MINOR% PATCH% BUILD); return text; ) boost :: uint64_t Version :: AsNumber () (BOOST_STATIC_ASSERT (BUILD< 0xFFFFFF ) ; using namespace boost; const size_t size = sizeof (uint64_t ) ; static const boost:: uint64_t number = (static_cast < uint64_t >(MAJOR)<< (size - sizeof (MAJOR) ) * 8 ) | (static_cast < uint64_t >(MINOR)<< (size - sizeof (MAJOR) - sizeof (MINOR) ) * 8 ) | (static_cast < uint64_t >(PATCH)<< (size - sizeof (MAJOR) - sizeof (MINOR) - sizeof (PATCH) ) * 8 ) | BUILD; return number; }

Everything is trivial here and, I think, does not require comments. The last thing left is the mechanism for changing the BUILD value to the revision number in the repository. CMake will handle this just fine, just add the following code to CMakeLists.txt:

set (VERSION_FILE ../ common / sources / version.cpp) find_package (Subversion REQUIRED) Subversion_WC_INFO ($ (PROJECT_SOURCE_DIR) Repo) file (READ $ (VERSION_FILE) OLD_CODE) foreach (LINE $ (OLD_CODEX)) "string = (+) "BUILD_NUMBER $ (LINE)) if (BUILD_NUMBER) string (REGEX REPLACE" + $ "$ (Repo_WC_REVISION) LINE $ (LINE)) endif () set (NEW_CODE $ (NEW_CODE) $ (LINE)) endforeach ( LINE) file (WRITE $ (VERSION_FILE) " $ (NEW_CODE) ")

The only subtlety in the script is in the last line, and more specifically, the quotes in "$ (NEW_CODE)", without them all “;” will be removed.

Foolproof is a set of measures to prevent the entry of incorrect information into a form. For example, if you need to enter a positive number from 0 to 10 in a field, then you should check that the user does not enter text or a number that does not lie in the specified range, i.e. the number must not be less than zero and more than ten.

Why is incorrect information being entered? This is mainly due to three reasons.

  1. The user made a mistake by accident, for example, inattentively read what he needs to indicate.
  2. On the web page, they are ambiguously asked to enter data, so the user has to guess and make an assumption about what they really want from him. At the same time, the opinions of the developer and the user do not always coincide.
  3. There are a number of people who take instructions as a challenge and try to do the opposite. Such users reason like this: “Yeah, I'm asked to enter a number. What happens if I indicate the letters? " After that, they ask obviously incorrect information and see what it will lead to.

It should be understood that precise and correct formulations, although they reduce the likelihood of errors, in no way save you from them. Only technical means on the server side allow you to get the desired result and avoid entering incorrect information. Nevertheless, revision or, as it is also called, client-side validation allows you to quickly check the data entered by the user for correctness, without submitting the form to the server. This saves the user time and reduces the load on the server. From the point of view of usability, there are also pluses - the user immediately receives a message about what information he indicated incorrectly and can correct his mistake.

Required field

Some form fields must be filled in before sending them to the server. This, for example, applies to the registration form, where you need to enter a username and password. The required attribute is used to specify required fields, as shown in Example 1.

Example 1. The required attribute

HTML5 IE 10+ Cr Op Sa Fx

Required field

Login:

Password:

Required fields must be filled in before submitting the form, otherwise the form will not be sent to the server and the browser will issue a warning about this. The form of the message depends on the browser, for example, Chrome displays a tooltip, as shown in Fig. 1.

Rice. 1. Required field is not filled

Correctness of data

Initially, there are two fields in which the data entered by the user is checked automatically. This is the web address and address Email... The Chrome browser also checks for the correctness of the calendar data field, but only because it does not have a click-to-select calendar interface. These elements are characterized by the following rules.

  • Web address ( ) must contain the protocol (http: //, https: //, ftp: //).
  • E-mail address ( ) must contain letters or numbers before the @ symbol, after it, then a period and a first-level domain.

Browsers have slightly different policies for verifying user data. For example, Opera automatically substitutes the http: // protocol in front of the entered text, while other browsers expect it from the user. Chrome and Opera require a dot to be in the mailing address, it is optional for Firefox.

Example 2 shows a form with required fields in which two fields are validated by the browser.

Example 2. Correctness of data

HTML5 IE 10+ Cr Op Sa Fx

Correctness of data

Fill out the form (all fields are required)

Name:

Email:

Site:

Opera only validates a form element if the name attribute is present.

What happens in Opera when you enter incorrect data is shown in Fig. 2.

Rice. 2. Warning about incorrect data

Input Template

Some data cannot be categorized as one type of form element, so you have to use a text box for it. Moreover, their input takes place according to a certain standard. So, the IP address contains four numbers separated by a dot (192.168.0.1), the postal code of Russia is limited to six digits (124007), the phone contains a city code and a specific number of digits often separated by a hyphen (391 555-341-42), etc. The browser needs specify an input template so that it validates user input according to it. For this, the pattern attribute is used, and its value is a regular expression. Some typical values ​​are listed in table. 1.

Example 3 asks for a hexadecimal color value (# ffcc00) and if it is not in this range, the browser displays an error message.

Example 3. Input Template

HTML5 IE 10+ Cr Op Sa Fx

Color input

Enter a hexadecimal color value (must start with #)

In fig. 3 shows a warning in the Chrome browser.

Rice. 3. The entered data does not match the template

Cancellation of validation

Validation is not always required for a form, for example, a developer wants to use a universal solution in JavaScript and he doesn't need duplicate validation by the browser. In such cases, you need to disable inline validation. For this, the novalidate attribute of the tag is applied.

... Example 4 shows the use of this attribute.

Example 4. Cancellation of validation

HTML5 IE 10+ Cr Op Sa Fx

Novalidate attribute

For a similar purpose, the formnovalidate attribute is applied, which is added to the button for submitting the form, in this case to the tag ... In this case, the form from example 4 will look like this.

Hi guys, hope things are going well, today we will be explaining a very useful tutorial with you. In today's tutorial, we will create a simple contact form using angularJS and php.

A contact form is a standard web page that is available on every site. This allows site visitors to contact the site owners or service providers who are responsible for maintaining this website. So we are thinking why not create a simple contact form using Angularjs and php to receive messages from websites, readers and / or users.

We are using Angularjs for the foreground and php on the server side. We will be writing a php code that takes data from an Angular form and sends it by email to the site administrator. Create a folder named “contact-form” in your web application directory and create a sample HTML page layout, index.html. Now copy and paste the code below into your index.html file.

Demo - Simple Contact Form with Angularjs and php

Contact form using angularjs and PHP


Php code for sending email

Create a contact.php page and copy paste the code below. Below is the php code that will fetch data from angular form and email it to the specified email address.

< ?php $post_data = file_get_contents("php://input"); $data = json_decode($post_data); //Just to display the form values echo "Name: " . $data->name; echo "Email:". $ data-> email; echo "Message:". $ data-> message; // sned an email $ to = $ data-> email; $ subject = "Test email angularjs testing site contact form"; $ message = $ data-> message; $ headers =" From: ". $ data-> name .." \ r \ n ".." \ r \ n "." X-Mailer: PHP / ". phpversion (); // function PHP mail to send email to the email address mail ($ to, $ subject, $ message, $ headers); ?>

For any web developer, there is no more serious problem yet than the complete cross-browser compatibility of his product. Perhaps this is one of the main tasks of a good specialist: to ensure that his site is always displayed correctly in all browsers.

Parameter required, which is sometimes used for input, does not work in ancient IE, which simply cannot be left like that. Retired users who still use IE6 should have the same ease of using your site as their users Google chrome latest version... Who, other than web developers, can take care of them.

About painful, about Internet Explorer

For normal browsers like Firefox, Opera and Google Chrome, this task is relatively easy. Even older versions of these browsers display html-code equally well, unless of course some new technology is used in it. But to achieve this in browsers of the family Internet Explorer, just titanic efforts are required.

Each version Internet browser Exlorer has its own unique stupidity. What works in IE6 may not work properly in IE7, and vice versa. This zoo of Microsoft has not been able to overcome even in the latest version of its browser.

I can't understand why browser developers can't just open up and read the W3C standards for site building.

Therefore, as a web developer, I have to act as a kind of "layer" between capricious browsers and site visitors requiring knowledge and spectacles. And it's great that web developers have succeeded so far.

So how do you get required to work in older versions of IE?

JS comes to the rescue. Previously, I could not stand it, but now I do not see any further way without it in the vastness of the "correct" WEB.

I did not invent the solution below myself, but took it from a bourgeois blog. Since I am greedy, and the blog is bourgeois, I will not provide a link to it.

The function will be responsible for everything. fnCheckFields ()... Place the JS code on your website:

It is usually recommended to place it between html tags HEAD at the beginning of the page, but I would still recommend placing it at the very bottom of the page before the closing tag BODY... Thus, JS has less impact on page load speed.

The input window, where the required parameter must be entered, should look like this in html language:

This script works very simply: after clicking the button send, the script checks all inputs for the presence of the required parameter and if it finds it, then it looks at the entered value of this field accordingly. If nothing is entered into such an input, then a warning window about the need for input is displayed. Accordingly, the data is not sent anywhere.

It is also great that if you have a normal browser that has already learned to understand this parameter as expected, such a warning window will not pop up and the standard tools for processing the required parameter for your browser will work.

Share on social media networks

Why was this form installed?

At the moment, a Brute-force attack is being carried out on your site. Brute-force attack is a brute-force attack. In this case, the password for the administrative panel of your site is brute-force.

In order to prevent hacking of your site and increase its security, we have installed additional protection.

How can I now access the admin panel of the site

Now, when you access the administrative panel of your site (on Joomla or WordPress), an additional window for entering your login and password will appear with the inscription "please use your control panel password". As a login, you must enter the login of your hosting service, it looks like "U1234567"... The password is the current password for your hosting service.

After passing basic HTTP authentication, you will see a standard authorization field in the admin panel of your site. Now you will need to enter the login and password of the site administrator.

How Basic HTTP Authentication Works

When entering a login-password in the basic authentication window, the value of the login and password hash will be compared with values ​​in a special file ~ / etc / users available in the hosting control panel. The content of the file looks something like this: "U1234567: dm48bspxIO3rg"... Where "u1234567" is the login, and "dm48bspxIO3rg" is password hash(note: only the hash, not the password itself!). A password hash is the result of a password conversion according to a certain algorithm.

Thus, when you enter your username and password in the basic authentication window, from the entered password is taken hash and is compared with the hash value in the file ~ / etc / users... If the values ​​match, you are authenticated.

I am unable to complete Basic Authentication

You are probably entering the wrong password. Install New Password for basic authentication:

If you have passed Basic Authentication but cannot log in directly to the admin panel of your Joomla or WordPress site, use the help:

How to increase the protection of a site against Brute-force attacks?

To increase the protection of the site:

  • change the superuser login to a more unique one. Do not use short names, it is better if you use the first name together with the last name. There are many resources on the Internet where the most popular logins are collected. Check them out and never use them;
  • set a strong site administrator password. Strong password must contain upper and lower case letters, numbers and additional characters such as "* - _ #:" etc. The length of the password is no less than 6 characters. Desirable from 10 and above.

How do I remove the Basic HTTP Authentication Form?

To remove the basic HTTP authentication form:

AuthType Basic AuthName "please use your control panel password" AuthUserFile ... / users Require valid-user

To comment out a line, put a hash mark ("#") at the beginning of the line, like this.