Making beautiful pop-up contact form with jQuery and jQuery UI. If JavaScript is disabled the form is usual.
Get jQuery UI:
Pick a theme or make your own and download it: jQuery UI. There is a part called "Overlay and Shadow Classes", that box is where we are going to put our form in. Get it with all features, meaning that check all the checkboxes.HTML code of popup:
We need both codes popup code and non popup code, if there is JavaScript enabled then we see the popup if not then we are taken to the page where our regular form is. Here is the code for the popup form:If you modify the form you might have to play with the style attributes, also if you get other style(I picked UI Lightness).Source code viewer
<!-- jQuery UI css file for the looks --> <link type="text/css" href="css/ui-lightness/jquery-ui-1.8.2.custom.css" rel="stylesheet" /> <!-- This makes the shadow --> <div class="ui-overlay"> </div> <!-- This is --> <div style="position:absolute;width:268px;height:360px;left:50px;top:30px;padding:10px;font-size:62.5%;font-style:Trebuchet MS ,sans-serif" class="ui-widget ui-widget-content ui-corner-all"> <div class="ui-dialog-content ui-widget-content" style="background:none;border:0"> <!-- Form start --> <input type="submit" /> <!-- Form end --> </div> </div>Programming Language: HTML
Link:
Now we need to make a link. That redirects if JavaScript is disabled or opens the popup if it's not disabled. Now save the form as html file, called form.html. There will be the form witch appears for users that don't have JavaScript. The popup comes by javascript. So here is my index.html file.I suggest to modify the file, put JavaScript to separate file and include it. Plus I would move all the HTML to on line.Source code viewer
<link type="text/css" href="css/ui-lightness/jquery-ui-1.8.2.custom.css" rel="stylesheet" /> <script type="text/javascript"> function contact_form(){ $("body").append('\ <div class="ui-overlay">\ </div>\ <div style="position:absolute;width:268px;height:360px;left:50px;top:30px;padding:10px;font-size:70%;font-style:Trebuchet MS ,sans-serif" class="ui-widget ui-widget-content ui-corner-all">\ <div class="ui-dialog-content ui-widget-content" style="background:none;border:0">\ <input type="submit" />\ </div>\ </div>'); } </script>Programming Language: HTML
Close button:
Here is how I made a nice little closing button. It's the HTML in our script.Source code viewer
function contact_form(){ <div class="ui-overlay">\ <div class="ui-widget-overlay"></div>\ <div class="ui-widget-shadow ui-corner-all" style="width:290px;height:382px;position:absolute;left:50px;top:30px"></div>\ </div>\ <div style="position:absolute;width:268px;height:360px;left:50px;top:30px;padding:10px;font-size:70%;font-style:Trebuchet MS ,sans-serif" class="ui-widget ui-widget-content ui-corner-all">\ <a href="#" onclick="javascript:$(\'#contact_popup\').remove()" style="float:right">X</a>\ <div class="ui-dialog-content ui-widget-content" style="background:none;border:0">\ <p><form action="url/of/your/php/script" method="post" id="contact_us">\ <label for="name">Name: </label><br><input type="text" name="name" /><br /><br />\ <label for="email">Email Address: </label><br><input type="text" name="email" /><br /><br />\ <label for="subject">Subject: </label><br><input type="text" name="subject" /><br /><br />\ <label for="message">Message: </label><br><textarea name="message" cols="48" rows="6"></textarea><br /><br />\ <input type="submit" />\ </form></p>\ </div>\ </div></div>'); }Programming Language: jQuery
And that's it, there are more cool features in jQuery UI. Like CSS buttons for example. If you are using CodeIgniter then you can combine this tutorial with "CodeIgniter AJAX Form Submission With jQuery" and you will get fully functional contact form with ajax.