BAC Software Consulting Blog

A Comprehensive Guide to Creating PHP Contact Form of the Nature of the iPhone Slider

To run a successful website, you need a concoction of several methodologies which combined pour in the best results for you. Now, among all those significant methodologies, collecting data pertaining to your website’s users – new and existing – is right up there among the most effective methods. And when you talk of collecting data and fetching the feedback from your users, contact form is the go-to source.

Due to the irreplaceable role played by contact forms that webmasters unfailingly rely on them for getting a good enough idea of whom they are interacting with and whether the service they are providing echoes with the requirements of their visitors. And that’s where creating highly interactive and sleek contact forms comes into play, since it remains a fact that humdrum forms hardly capture the attention of users and end up being totally ignored.

Now, from the last few years, owing to the rising importance of creating great contact forms, PHP has played a pivotal role since the PHP-built contact forms give the webmasters a whole array of options at their behest. That said, even though they are functionally very rich and accomplished, the overall visual appeal lacks in certain respects that eventually leads to not so great numbers being achieved. For many websites, the contact form is a direct way to the conversion rates or the lack of it, so with each user not deciding to fill the contact form, they lose a potential customer. Thus, with PHP already being well equipped to build fully functional forms, let’s see how we can add an attractive visual interface to the form. And what’s better than having something that looks like the iPhone slider – abundantly sleek and user friendly.

Features of the iPhone Slider Contact Form

As an example, let’s take the contact form shown in the picture at the beginning of this post. The form looks suave and tailored for user friendliness, and the “Slide to Send” button further adds to both the facets.

What this contact form essentially has is a Javascript validation. This validation ensures that the loading of the page fails when you are putting in data that does not follow certain patterns or is required. One of the features that makes this form even more significantly important is the fact that you do not need Captcha with it, since the Slide to Send feature works as a perfect replacement. So if you are already wondering how to prevent spam from pouring in without Captcha, rest assured that this slide button will do the job in a highly efficient manner. You won’t need Captcha or any other anti comment spammer tool.

As far as the styling of the form is concerned, it gets its styling from the rich CSS3 language. It is not a concealed fact anymore that CSS3 can help you build awesome designs of which are not possible with other languages or with the previous CSS versions.

Now, what we have done with the form to make it even more dynamic, usable and attractive, we have gone on to adding Google Map feature to it, that takes its functional abilities to a new level. You can make the necessary changes to the google Map, depending on your location.

All you got to do is to is to upload the files (DEMO IS AT THE END OF THIS POST) to your web server and make some tweaks to the mailfunction.php file located in the process folder.

Since you are not able to view the source code of the “mailfunction.php” file, I am including the code below. There are 2 lines of code that you need to change: Line 4 with your email address and Line 25, replace ‘WEBSITENAME’ with your domain name.

  <?php
    //email receiver and subject//
    $emailSubject = 'Slide to Send Contact Form Response';
    $sendemailto = 'name@domain.com';  /*** Change this to your email address ***/
     
    //declare our assets//
    $nameField = $_POST['name'];
    $emailField = $_POST['email'];
    $phoneField = $_POST['phone'];
    $companyField = $_POST['company'];
    $addressField = $_POST['address'];
    $messageField = $_POST['message']; 
     
    $body = <<<EOD
<br><br>
Name: $nameField <br>
Email: $emailField <br>
Phone: $phoneField <br>
Company: $companyField <br>
Address: $addressField <br>
Message: $messageField <br>
EOD;
 
/*** Change 'WEBSITENAME' to your DOMAIN name ***/
    $headers = 'From: '.WEBSITENAME.'' . "\r\n" .
    'Reply-To: '.$emailField.'' . "\r\n" .
    'Content-type: text/html; charset=utf-8' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
    $success = mail($sendemailto, $emailSubject, $body, $headers);
     
if($success){
   echo 'OK';
 }
else{
   echo 'NOT OK';
}           
?>

Changing the Google Map

Below is the google Map code that I am using in the index.html file. I am using Boston, MA as a reference point. You can choose your preferable location in Google Maps. On the embed link option, simply replace the link source of your choice.

<!--Google Map Iframe.-->           
<iframe width="96%" height="150" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://www.google.com/maps/embed?pb=!1m19!1m12!1m3!1d94411.73947848775!2d-71.05715705!3d42.31337345!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!4m4!1i0!3e1!4m0!4m0!5e0!3m2!1sen!2sus!4v1422794887869" style="border:0"></iframe><br />

An Overview of CSS3 Media Queries

The rapid use of Smart phones and mobile devices have changed the way information is processed and made available to the web audience. The surprising growth of such devices is leapfrogging the traditional desktops, making users view a website on mobile phones and tablet devices anytime, anywhere.

When talking about such web designs that should compliment the various dimensions of different devices, it is difficult not to mention about the challenges that web designers face while creating them. CSS3 media queries are a great way to overcome such challenges and making web designs look amazing, while providing a pleasurable experience to each type of user.

As a part of CSS3 specification, these media queries determine the role of the media and control how styling should be applied to them. They allow web designers target different styles based on multiple specifications of a device such as screen size, orientation, color and so on.

This article provides you an overview of media queries that will help designers kick start their multi screen website development endeavors.

CSS3 Media Queries

CSS 2.1 supports several media types based on “media type” declarations. The following mark up clearly explains about how media types can be used to specify conditional style sheets.

<link rel="stylesheet" type="text/css" href="main.css" media="screen" />
<link rel="stylesheet" type="text/css" href="print.css" media="print" />

When placed correctly, the site will load a different stylesheet from the default sheet, when set in a print preview mode. The feature is useful but often remain underutilized because of its incapability to provide valuable contextual clues for developing a responsive website. As only 10 media types are being used by the media specifications, browsers often fail to adapt complete media specifications.

The “media” attribute plays a significant role in determining various media related element of a web page. It helps you specify media type on the basis of screen, print and more and also let you incorporate various expressions that include width, height, orientation, screen resolution etc., of the device being used. Here, we are giving you an example of a device that’s media type is screen and resolution is 720 pixels.

<link rel="stylesheet" media="screen and (min-width: 720px)" href="main.css" />

It’s the media query that determines the overall designing process. The left side highlights those properties of a design that needs to be tested, and gives an option ranging from min-max. The right is the actual value of the tested property. If the browser and the mobile having 720 pixels of screen width, the style.css will be implemented by the webmasters. This way, it can be said that media queries an indeed useful to give developers an insight about the context to develop web pages that are truly responsive.

Ways to Define Media Queries

A simple media query in HTML can be written like this:

<link rel="stylesheet" media="width" ref="abc.css" />

In the above example, we have stated that for width media query, abc.css style sheet needs to be used.

The same can also be written in import form:

@import url(abz.css) print; 

In cases where no media type is given or ‘all’ is specified, the styling would be done like this:

<link rel="stylesheet" href="abc.css" />
<link rel="stylesheet" media="all" ref="abc.css" />

One can also combine the media queries to create a complex structure:

<link rel="stylesheet" media="width, projection" href="abc.css" />

this can also be written like this:

@media width, projection { … }

Using Media Queries for Multiple and Single Style Sheets

Creating multiple style sheets to suit the requirements of different device screens and sizes can be daunting. However, if you still want to create multiple style sheets, this is how you can do so:

<link rel="stylesheet" media="screen and (max-width: 800px)" href="small.css" />
<link rel="stylesheet" media="screen and (min-width: 800px)" href="large.css" />
<link rel="stylesheet" media="print" href="print.css" />

To boost the productivity, it is recommended to incorporate multiple style sheets created for different browsers and screen into a common one. Here’s how you can go through it.

@media screen and (min-width: 800px) {
  .eighthundredminwidthclass {
    width: 35%;
    Float: right;
 } 
}
and
@media screen and (max-width: 800px) {
    .eighthundredmaxwidth {
    clear: both;
    font-size: 1.5em;
    }
}

You must have noticed the use of max-width in the above and min-width on the below examples. It is important to know the difference between the two. In the case of desktop, it is easy to understand. Min-width and max-width refer to the size of the browser viewport, while max-device-width and min-device-width are applied for hand held devices.

Conclusion

CSS3 media queries are the heart of a responsive web design, therefore, should be used logically. It’s about presenting an information that meets the demands of both web browsers and hand held devices.