{"id":10301,"date":"2011-08-23T21:03:16","date_gmt":"2011-08-23T13:03:16","guid":{"rendered":"https:\/\/www.hongkiat.com\/blog\/?p=10301"},"modified":"2025-04-04T00:43:13","modified_gmt":"2025-04-03T16:43:13","slug":"ajax-html5-css3-contact-form-tutorial","status":"publish","type":"post","link":"https:\/\/www.hongkiat.com\/blog\/ajax-html5-css3-contact-form-tutorial\/","title":{"rendered":"How to Build an Ajax-Based HTML5 Contact Form"},"content":{"rendered":"<p>A contact form is crucial for any website as it serves as a conduit, allowing visitors to relay their thoughts or queries directly to the webmaster. While there are numerous contact <a href=\"https:\/\/www.hongkiat.com\/blog\/login-registration-form\/\">forms<\/a> available online, many lack detailed explanations of their internal workings. This comprehensive tutorial will guide you through creating an advanced contact form from scratch, utilizing popular technologies like <a href=\"https:\/\/www.hongkiat.com\/blog\/tag\/html\/\">HTML5<\/a> and <a href=\"https:\/\/www.hongkiat.com\/blog\/tag\/css\/\">CSS3<\/a>.<\/p>\n<p>This task requires knowledge of both front-end and back-end development. We\u2019ll explore PHP for the backend to handle email sending and jQuery to enhance the user interface. By the end of this tutorial, you will have a fully dynamic and functional contact form that is designed with future customization in mind.<\/p>\n<p><a href=\"https:\/\/assets.hongkiat.com\/uploads\/html5-css3-contact-form\/html5-css3-contact-form.zip\" class=\"su-button su-button-style-flat\" style=\"color:#FFFFFF;background-color:#2D89EF;border-color:#246ec0;border-radius:0px\" target=\"__blank\" rel=\"noopener nofollow\"><span style=\"color:#FFFFFF;padding:7px 20px;font-size:16px;line-height:24px;border-color:#6cadf4;border-radius:0px;text-shadow:none\"><i class=\"sui sui-external-link\" style=\"font-size:16px;color:#fff\"><\/i>  Download files <\/span><\/a><\/p>\n<h2>Setting Up Your Development Environment<\/h2>\n<p>To begin, you\u2019ll need a web server. For those on a Windows platform, <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.wampserver.com\/en\/\">WAMP<\/a> is an excellent choice. Mac users can opt for a <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.mamp.info\/de\/en\/index.html\">similar solution called MAMP<\/a>, which is equally straightforward to install.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/html5-css3-contact-form\/wampserver.jpg\" alt=\"WAMP Server setup\" width=\"500\" height=\"355\"><\/figure>\n<p>These applications provide a local server environment on your computer, allowing full access to PHP. Alternatively, if you have access to your own server space or can connect to a remote server, that could be used as well. No MySQL databases are required for this project, which simplifies the setup.<\/p>\n<p>After your server is ready, <strong>create a new folder to store the application<\/strong>. You can name it anything as it does not impact the final result. This folder structure will come into play when accessing your files through a web browser, like in the example <strong>http:\/\/localhost\/ajaxcontact\/contact.php<\/strong><\/p>\n<h2>Creating Our Core Files<\/h2>\n<p>We will be working with two primary files. First, we need a <em>.php<\/em> file that will contain both our application logic and the front-end HTML markup. Below is a sample code snippet from our starting file.<\/p>\n<pre>\r\n&lt;!DOCTYPE html&gt;\r\n&lt;html xmlns:fb=\"https:\/\/www.facebook.com\/\/2008\/fbml\" xml:lang=\"en\" lang=\"en\"&gt;\r\n&lt;head&gt;\r\n  &lt;title&gt;HTML5\/CSS Ajax Contact Form with jQuery&lt;\/title&gt;\r\n  &lt;script type=\"text\/javascript\" src=\"http:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.4.2\/jquery.min.js\"&gt;&lt;\/script&gt;\r\n  &lt;link href=\"styles.css\" rel=\"stylesheet\" type=\"text\/css\"\/&gt;\r\n&lt;\/head&gt;\r\n<\/pre>\n<p>We start with a simple header section in our document. It includes a <strong>Doctype declaration for HTML5<\/strong>, and various HTML\/XML elements that, while not strictly necessary, help ensure consistent rendering across different browsers. Additionally, providing more information generally enhances compatibility and functionality.<\/p>\n<p>Further in the document, just before the closing head tag, we include two crucial lines. The first line adds a <strong>jQuery script from the Google Code Repository<\/strong>, essential for handling dynamic page functionalities. Right below that, we link a basic <strong>CSS file<\/strong> that applies styles to our webpage.<\/p>\n<p>In the document body, we feature several <strong>container divisions<\/strong> that encapsulate the main contact form. This form includes input fields for the <strong>user\u2019s name<\/strong>, <strong>e-mail address<\/strong>, and <strong>personal message<\/strong>. The HTML structure is straightforward and should be easily understood by an intermediate developer.<\/p>\n<pre>\r\n&lt;!-- @begin contact --&gt;\r\n&lt;div id=\"contact\" class=\"section\"&gt;\r\n  &lt;div class=\"container content\"&gt;\r\n\r\n  &lt;?php if(isset($emailSent) && $emailSent == true) { ?&gt;\r\n    &lt;p class=\"info\"&gt;Your email was sent. Huzzah!&lt;\/p&gt;\r\n  &lt;?php } else { ?&gt;\r\n<\/pre>\n<p>Here, we have straightforward <strong>PHP conditional code<\/strong> embedded within a few page containers. It checks whether a variable named <code>$emailSent<\/code> is set and true, displaying a success message if the conditions are met.<\/p>\n<h2>Details of the Form HTML Structure<\/h2>\n<p>The <strong>else<\/strong> statement will be executed on the initial page load when no data has been sent. This section includes a <strong>collection of form elements<\/strong> and a <strong>submit button<\/strong>.<\/p>\n<pre>\r\n&lt;div id=\"contact-form\"&gt;\r\n  &lt;?php if(isset($hasError) || isset($captchaError)) { ?&gt;\r\n    &lt;p class=\"alert\"&gt;Error submitting the form&lt;\/p&gt;\r\n  &lt;?php } ?&gt;\r\n\r\n  &lt;form id=\"contact-us\" action=\"contact.php\" method=\"post\"&gt;\r\n    &lt;div class=\"formblock\"&gt;\r\n      &lt;label class=\"screen-reader-text\"&gt;Name&lt;\/label&gt;\r\n      &lt;input type=\"text\" name=\"contactName\" id=\"contactName\" value=\"&lt;?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?&gt;\" class=\"txt requiredField\" placeholder=\"Name:\"\/&gt;\r\n\r\n      &lt;?php if($nameError != '') { ?&gt;\r\n        &lt;br\/&gt;&lt;span class=\"error\"&gt;&lt;?php echo $nameError;?&gt;&lt;\/span&gt; \r\n      &lt;?php } ?&gt;\r\n    &lt;\/div&gt;\r\n\r\n    &lt;div class=\"formblock\"&gt;\r\n      &lt;label class=\"screen-reader-text\"&gt;Email&lt;\/label&gt;\r\n      &lt;input type=\"text\" name=\"email\" id=\"email\" value=\"&lt;?php if(isset($_POST['email'])) echo $_POST['email'];?&gt;\" class=\"txt requiredField email\" placeholder=\"Email:\"\/&gt;\r\n\r\n      &lt;?php if($emailError != '') { ?&gt;\r\n        &lt;br\/&gt;&lt;span class=\"error\"&gt;&lt;?php echo $emailError;?&gt;&lt;\/span&gt;\r\n      &lt;?php } ?&gt;\r\n    &lt;\/div&gt;\r\n\r\n    &lt;div class=\"formblock\"&gt;\r\n      &lt;label class=\"screen-reader-text\"&gt;Message&lt;\/label&gt;\r\n      &lt;textarea name=\"comments\" id=\"commentsText\" class=\"txtarea requiredField\" placeholder=\"Message:\"&gt;&lt;?php if(isset($_POST['comments'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['comments']); } else { echo $_POST['comments']; } } ?&gt;&lt;\/textarea&gt;\r\n\r\n      &lt;?php if($commentError != '') { ?&gt;\r\n        &lt;br\/&gt;&lt;span class=\"error\"&gt;&lt;?php echo $commentError;?&gt;&lt;\/span&gt; \r\n      &lt;?php } ?&gt;\r\n    &lt;\/div&gt;\r\n\r\n    &lt;button name=\"submit\" type=\"submit\" class=\"subbutton\"&gt;Send us Mail!&lt;\/button&gt;\r\n    &lt;input type=\"hidden\" name=\"submitted\" id=\"submitted\" value=\"true\"\/&gt;\r\n  &lt;\/form&gt;\r\n&lt;\/div&gt;\r\n\r\n&lt;?php } ?&gt;\r\n&lt;\/div&gt;\r\n&lt;\/div&gt;&lt;!-- End #contact --&gt;\r\n<\/pre>\n<p>Notice the additional <strong>conditional block<\/strong> immediately following the form\u2019s start. It checks for errors using variables like <code>$hasError<\/code> and displays an error message if any are found. This method acts as a fallback when JavaScript is disabled, as the dynamic error handling won\u2019t function.<\/p>\n<p>Further down, we handle <strong>individual PHP error checks<\/strong> for each input field. These checks ensure that even if the form is submitted with incomplete data, the filled fields will retain their values, enhancing the user experience.<\/p>\n<p>Following the form, there are several <strong>jQuery functions<\/strong> implemented. We\u2019ll discuss these first since they are the default handling method on page load. However, if JavaScript is not supported by the browser, the PHP code will serve as a reliable fallback.<\/p>\n<h2>Introduction to jQuery<\/h2>\n<p>The best way to start discussing jQuery is to dive straight into an example. I will break down individual blocks of code line-by-line so you can understand what the script checks for.<\/p>\n<p>If you find yourself getting lost, simply <strong>review the project code files<\/strong>. All code blocks are pre-written and well-documented on the <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/jquery.com\/\">jQuery website<\/a>. We begin our code in a standard manner:<\/p>\n<pre>\r\n&lt;script type=\"text\/javascript\"&gt;\r\n  &lt;!--\/\/--&gt;&lt;![CDATA[\/\/&gt;&lt;!--\r\n  $(document).ready(function() {\r\n    $('form#contact-us').submit(function() {\r\n<\/pre>\n<p>The initial lines <strong>check for specific events<\/strong>. After using CDATA comments to shield the script from older browsers, we start by checking if the document is ready for manipulation \u2013 a fundamental jQuery practice.<\/p>\n<p>We then look for submissions of a form with the ID \u201c<strong>contact-us<\/strong>\u201c, which triggers another function that handles either displaying error messages or executing a <code>slideUp()<\/code> effect upon successful submission.<\/p>\n<pre>\r\n$('form#contact-us .error').remove();\r\nvar hasError = false;\r\n$('.requiredField').each(function() {\r\n  if($.trim($(this).val()) == '') {\r\n    var labelText = $(this).prev('label').text();\r\n    $(this).parent().append('&lt;span class=\"error\"&gt;You forgot to enter your '+labelText+'.&lt;\/span&gt;');\r\n    $(this).addClass('inputError');\r\n    hasError = true;\r\n  } else if($(this).hasClass('email')) {\r\n    var emailReg = \/^([\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4})?$\/;\r\n    if(!emailReg.test($.trim($(this).val()))) {\r\n      var labelText = $(this).prev('label').text();\r\n      $(this).parent().append('&lt;span class=\"error\"&gt;Sorry! You\\'ve entered an invalid '+labelText+'.&lt;\/span&gt;');\r\n      $(this).addClass('inputError');\r\n      hasError = true;\r\n    }\r\n  }\r\n});\r\n<\/pre>\n<p>We begin by removing any existing error messages to ensure we start fresh. Next, we target elements with the class \u201c<strong>requiredField<\/strong>\u201c, which include the name, e-mail, and message fields.<\/p>\n<p>jQuery checks each field\u2019s value and alerts the user if it is empty, or if the e-mail does not match the regular expression pattern, indicating an invalid input.<\/p>\n<p>If no errors are found, we proceed to submit the form via jQuery\u2019s <code>post()<\/code> method. Assuming no server-side errors, a <code>slideUp()<\/code> animation is used to hide the form and show a \u201c<strong>success!<\/strong>\u201d message.<\/p>\n<pre>\r\nif(!hasError) {\r\n  var formInput = $(this).serialize();\r\n  $.post($(this).attr('action'), formInput, function(data){\r\n    $('form#contact-us').slideUp(\"fast\", function() { \r\n      $(this).before('&lt;p class=\"tick\"&gt;&lt;strong&gt;Thanks!&lt;\/strong&gt; Your email has been delivered. Huzzah!&lt;\/p&gt;');\r\n    });\r\n  });\r\n}\r\n\r\nreturn false; \r\n});\r\n});\r\n\/\/--&gt;!]]&gt;\r\n&lt;\/script&gt;\r\n<\/pre>\n<p>The use of <strong>callbacks<\/strong> in jQuery is also demonstrated here. A callback is a smaller function called in response to data received from another function. For instance, when our <code>jQuery.post()<\/code> successfully sends an email, it triggers a function that initiates the sliding animation. This approach allows us to keep the callback inline for simplicity in this tutorial.<\/p>\n<h2>Navigating Through Our PHP Logic<\/h2>\n<p>The final key component to discuss is the <strong>logic<\/strong> behind our PHP backend. This system is responsible for <strong>invoking a mail function<\/strong> and <strong>sending out the message<\/strong>. You can find all the code for this at the top of our main <em>.php<\/em> file, before any HTML is output.<\/p>\n<p>Additionally, a few internal styles help enhance the page\u2019s appearance. There isn\u2019t anything particularly new here, so we won\u2019t delve into details. The <em>styles.css<\/em> file included in the project uses basic CSS3 techniques.<\/p>\n<pre>\r\n&lt;?php \r\n\/\/ If the form is submitted\r\nif(isset($_POST['submitted'])) {\r\n<\/pre>\n<p>We begin by checking <strong>if the form was submitted<\/strong>, using the <strong>POST<\/strong> variable \u201c<strong>submitted<\/strong>\u201d which is a hidden input field placed at the end of our form. This check helps avoid unnecessary server resource use if no data has been submitted.<\/p>\n<p>Following this, we have three separate <strong>if\/else<\/strong> statements checking <strong>if each input field is filled out<\/strong>. Here\u2019s an example of the e-mail verification logic:<\/p>\n<pre>\r\n\/\/ Need valid email\r\nif(trim($_POST['email']) === '') {\r\n  $emailError = 'Forgot to enter in your e-mail address.';\r\n  $hasError = true;\r\n} else if (!preg_match(\"\/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\\.[a-z]{2,4}$\/i\", trim($_POST['email']))) {\r\n  $emailError = 'You entered an invalid email address.';\r\n  $hasError = true;\r\n} else {\r\n  $email = trim($_POST['email']);\r\n}\r\n<\/pre>\n<p>PHP trims all whitespace from the email value and verifies it against a <strong>Regular Expression (Regex)<\/strong> to ensure it matches a typical email pattern.<\/p>\n<p>You don\u2019t need to be an expert in <code>preg_match()<\/code> to use this script. It\u2019s a powerful function used to <strong>enforce specific data types and patterns<\/strong>, like ensuring an email includes valid characters and a domain.<\/p>\n<p>Once all checks are passed with no errors, it\u2019s time to send our message! Here\u2019s how we configure the email parameters and headers:<\/p>\n<pre>\r\n\/\/ Upon no failure errors, let's email now!\r\nif(!isset($hasError)) {\r\n  $emailTo = 'youremailhere@googlemail.com';\r\n  $subject = 'Submitted message from '.$name;\r\n  $sendCopy = trim($_POST['sendCopy']);\r\n  $body = \"Name: $name \\n\\nEmail: $email \\n\\nComments: $comments\";\r\n  $headers = 'From: ' .' &lt;'.$emailTo.'&gt;' . \"\\r\\n\" . 'Reply-To: ' . $email;\r\n\r\n  mail($emailTo, $subject, $body, $headers);\r\n  \r\n  \/\/ Set our boolean completion value to TRUE\r\n  $emailSent = true;\r\n}\r\n<\/pre>\n<p>If you\u2019ve ever wondered how the script identifies your email address to send messages to, here\u2019s where you specify it in the <code>$emailTo<\/code> variable.<\/p>\n<p>The <code>$body<\/code> of the email uses the \\n delimiter to format the message with lines for the sender\u2019s name, email address, and their message content. This format is simple yet effective for reading the message clearly.<\/p>\n<h2>Conclusion<\/h2>\n<p>This concludes our tutorial on creating an advanced contact form. If you want to style your elements similar to the provided example, you can refer to the <em>styles.css<\/em> file included in the project. However, the structure is straightforward enough that you could easily design your own aesthetic.<\/p>\n<p>Feel free to <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/assets.hongkiat.com\/uploads\/html5-css3-contact-form\/html5-css3-contact-form.zip\">download the source code<\/a> to examine the project more closely. It\u2019s beneficial to follow a tutorial, but accessing the source directly can be invaluable. A brief stylesheet is also included to facilitate easy customizations. Thanks for following along!<\/p>","protected":false},"excerpt":{"rendered":"<p>A contact form is crucial for any website as it serves as a conduit, allowing visitors to relay their thoughts or queries directly to the webmaster. While there are numerous contact forms available online, many lack detailed explanations of their internal workings. This comprehensive tutorial will guide you through creating an advanced contact form from&hellip;<\/p>\n","protected":false},"author":18,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3392,352],"tags":[507,1312,506,2016],"topic":[4520],"class_list":["entry-content","is-maxi"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v22.8 (Yoast SEO v27.6) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to Build an Ajax-Based HTML5 Contact Form - Hongkiat<\/title>\n<meta name=\"description\" content=\"A contact form is crucial for any website as it serves as a conduit, allowing visitors to relay their thoughts or queries directly to the webmaster. While\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.hongkiat.com\/blog\/ajax-html5-css3-contact-form-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Build an Ajax-Based HTML5 Contact Form\" \/>\n<meta property=\"og:description\" content=\"A contact form is crucial for any website as it serves as a conduit, allowing visitors to relay their thoughts or queries directly to the webmaster. While\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.hongkiat.com\/blog\/ajax-html5-css3-contact-form-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"Hongkiat\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/hongkiatcom\" \/>\n<meta property=\"article:published_time\" content=\"2011-08-23T13:03:16+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-03T16:43:13+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/assets.hongkiat.com\/uploads\/html5-css3-contact-form\/wampserver.jpg\" \/>\n<meta name=\"author\" content=\"Jake Rocheleau\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:site\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jake Rocheleau\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/ajax-html5-css3-contact-form-tutorial\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/ajax-html5-css3-contact-form-tutorial\\\/\"},\"author\":{\"name\":\"Jake Rocheleau\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/966b2daea15283b4145e71aa98a82c2a\"},\"headline\":\"How to Build an Ajax-Based HTML5 Contact Form\",\"datePublished\":\"2011-08-23T13:03:16+00:00\",\"dateModified\":\"2025-04-03T16:43:13+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/ajax-html5-css3-contact-form-tutorial\\\/\"},\"wordCount\":1331,\"commentCount\":46,\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/ajax-html5-css3-contact-form-tutorial\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/html5-css3-contact-form\\\/wampserver.jpg\",\"keywords\":[\"CSS\",\"Forms\",\"HTML\",\"HTML5 \\\/ CSS3 Tutorials\"],\"articleSection\":[\"Coding\",\"Web Design\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/ajax-html5-css3-contact-form-tutorial\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/ajax-html5-css3-contact-form-tutorial\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/ajax-html5-css3-contact-form-tutorial\\\/\",\"name\":\"How to Build an Ajax-Based HTML5 Contact Form - Hongkiat\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/ajax-html5-css3-contact-form-tutorial\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/ajax-html5-css3-contact-form-tutorial\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/html5-css3-contact-form\\\/wampserver.jpg\",\"datePublished\":\"2011-08-23T13:03:16+00:00\",\"dateModified\":\"2025-04-03T16:43:13+00:00\",\"description\":\"A contact form is crucial for any website as it serves as a conduit, allowing visitors to relay their thoughts or queries directly to the webmaster. While\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/ajax-html5-css3-contact-form-tutorial\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/ajax-html5-css3-contact-form-tutorial\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/ajax-html5-css3-contact-form-tutorial\\\/#primaryimage\",\"url\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/html5-css3-contact-form\\\/wampserver.jpg\",\"contentUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/html5-css3-contact-form\\\/wampserver.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/ajax-html5-css3-contact-form-tutorial\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Build an Ajax-Based HTML5 Contact Form\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"name\":\"Hongkiat\",\"description\":\"Tech and Design Tips\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\",\"name\":\"Hongkiat.com\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"contentUrl\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"width\":1200,\"height\":799,\"caption\":\"Hongkiat.com\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/hongkiatcom\",\"https:\\\/\\\/x.com\\\/hongkiat\",\"https:\\\/\\\/www.pinterest.com\\\/hongkiat\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/966b2daea15283b4145e71aa98a82c2a\",\"name\":\"Jake Rocheleau\",\"description\":\"Jake is a writer and designer with over 10 years experience working on the web. He writes about user experience design and cool resources for designers\",\"sameAs\":[\"https:\\\/\\\/www.hongkiat.com\"],\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/author\\\/jake\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Build an Ajax-Based HTML5 Contact Form - Hongkiat","description":"A contact form is crucial for any website as it serves as a conduit, allowing visitors to relay their thoughts or queries directly to the webmaster. While","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.hongkiat.com\/blog\/ajax-html5-css3-contact-form-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"How to Build an Ajax-Based HTML5 Contact Form","og_description":"A contact form is crucial for any website as it serves as a conduit, allowing visitors to relay their thoughts or queries directly to the webmaster. While","og_url":"https:\/\/www.hongkiat.com\/blog\/ajax-html5-css3-contact-form-tutorial\/","og_site_name":"Hongkiat","article_publisher":"https:\/\/www.facebook.com\/hongkiatcom","article_published_time":"2011-08-23T13:03:16+00:00","article_modified_time":"2025-04-03T16:43:13+00:00","og_image":[{"url":"https:\/\/assets.hongkiat.com\/uploads\/html5-css3-contact-form\/wampserver.jpg","type":"","width":"","height":""}],"author":"Jake Rocheleau","twitter_card":"summary_large_image","twitter_creator":"@hongkiat","twitter_site":"@hongkiat","twitter_misc":{"Written by":"Jake Rocheleau","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.hongkiat.com\/blog\/ajax-html5-css3-contact-form-tutorial\/#article","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/ajax-html5-css3-contact-form-tutorial\/"},"author":{"name":"Jake Rocheleau","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/966b2daea15283b4145e71aa98a82c2a"},"headline":"How to Build an Ajax-Based HTML5 Contact Form","datePublished":"2011-08-23T13:03:16+00:00","dateModified":"2025-04-03T16:43:13+00:00","mainEntityOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/ajax-html5-css3-contact-form-tutorial\/"},"wordCount":1331,"commentCount":46,"publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/ajax-html5-css3-contact-form-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/assets.hongkiat.com\/uploads\/html5-css3-contact-form\/wampserver.jpg","keywords":["CSS","Forms","HTML","HTML5 \/ CSS3 Tutorials"],"articleSection":["Coding","Web Design"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.hongkiat.com\/blog\/ajax-html5-css3-contact-form-tutorial\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.hongkiat.com\/blog\/ajax-html5-css3-contact-form-tutorial\/","url":"https:\/\/www.hongkiat.com\/blog\/ajax-html5-css3-contact-form-tutorial\/","name":"How to Build an Ajax-Based HTML5 Contact Form - Hongkiat","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/ajax-html5-css3-contact-form-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/ajax-html5-css3-contact-form-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/assets.hongkiat.com\/uploads\/html5-css3-contact-form\/wampserver.jpg","datePublished":"2011-08-23T13:03:16+00:00","dateModified":"2025-04-03T16:43:13+00:00","description":"A contact form is crucial for any website as it serves as a conduit, allowing visitors to relay their thoughts or queries directly to the webmaster. While","breadcrumb":{"@id":"https:\/\/www.hongkiat.com\/blog\/ajax-html5-css3-contact-form-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.hongkiat.com\/blog\/ajax-html5-css3-contact-form-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hongkiat.com\/blog\/ajax-html5-css3-contact-form-tutorial\/#primaryimage","url":"https:\/\/assets.hongkiat.com\/uploads\/html5-css3-contact-form\/wampserver.jpg","contentUrl":"https:\/\/assets.hongkiat.com\/uploads\/html5-css3-contact-form\/wampserver.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/www.hongkiat.com\/blog\/ajax-html5-css3-contact-form-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.hongkiat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Build an Ajax-Based HTML5 Contact Form"}]},{"@type":"WebSite","@id":"https:\/\/www.hongkiat.com\/blog\/#website","url":"https:\/\/www.hongkiat.com\/blog\/","name":"Hongkiat","description":"Tech and Design Tips","publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.hongkiat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.hongkiat.com\/blog\/#organization","name":"Hongkiat.com","url":"https:\/\/www.hongkiat.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","contentUrl":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","width":1200,"height":799,"caption":"Hongkiat.com"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/hongkiatcom","https:\/\/x.com\/hongkiat","https:\/\/www.pinterest.com\/hongkiat\/"]},{"@type":"Person","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/966b2daea15283b4145e71aa98a82c2a","name":"Jake Rocheleau","description":"Jake is a writer and designer with over 10 years experience working on the web. He writes about user experience design and cool resources for designers","sameAs":["https:\/\/www.hongkiat.com"],"url":"https:\/\/www.hongkiat.com\/blog\/author\/jake\/"}]}},"jetpack_featured_media_url":"https:\/\/","jetpack_shortlink":"https:\/\/wp.me\/p4uxU-2G9","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/10301","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/comments?post=10301"}],"version-history":[{"count":4,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/10301\/revisions"}],"predecessor-version":[{"id":73503,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/10301\/revisions\/73503"}],"wp:attachment":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/media?parent=10301"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/categories?post=10301"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/tags?post=10301"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/topic?post=10301"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}