Skip to main content

HTML 5 Form Validations

HTML 5 has introduced Javascript plug-ins to achieve something similar effect.

But these code will only work in Safari 5, Chrome 6, Opera 9, Firefox 4 Beta and the iPhone/iPad. Also each browser has a slightly different default behaviour.

The "required " attribute

The simplest change you can make to your forms is to mark a text input field as 'required':





Syntax:
Your Name: <input type="text" name="name" required>

That's it. And you are done. No need to use any javascript and CSS. Isn't that so cool.

Example:

<?php
$msg="";
$email="";
if(isset($_POST['sent']))
{if(isset($email))
    {
       
    $msg="Your email is ".$email;
    }
    else {
        $msg="Enter email.";
    }
   
   
}

?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome to this APP</title>
<style type="text/css">
#mainHolder{
    margin:0px auto;
    width:500px;
}
</style>
</head>

<body>
<div id="mainHolder">
 <form action="" method="post" >
<a href="index.php">Refresh</a>
<fieldset>
<legend>Sent Email</legend>
    <p> <?php if(isset($msg)){ echo $msg;}?>
    <p>Enter email <input type="input" name="email"  required /></p>
    <p><input type="submit" value="Sent" name="sent" /></p>
</fieldset>
</form>
</div>
</body>
</html>

Output in Mozilla:









Output in Chrome:








Woow.......Try it yourself :)

Comments

  1. I can’t remember the last time I enjoyed an article as much as this one. You have gone beyond my expectations on this topic and I agree with your points. You’ve done well with this. ui/ux design

    ReplyDelete
  2. This is getting a bit more subjective, but I much prefer the Zune Marketplace. The interface is colorful, has more flair, and some cool features like ‘Mixview’ that let you quickly see related albums, songs, or other users related to what you’re listening to. Clicking on one of those will center on that item, and another set of “neighbors” will come into view, allowing you to navigate around exploring by similar artists, songs, or users. Speaking of users, the Zune “Social” is also great fun, letting you find others with shared tastes and becoming friends with them. You then can listen to a playlist created based on an amalgamation of what all your friends are listening to, which is also enjoyable. Those concerned with privacy will be relieved to know you can prevent the public from seeing your personal listening habits if you so choose. interface designer

    ReplyDelete
  3. Thanks for sharing excellent informations. Your web-site is very cool. I'm impressed by the details that you have on this web site. It reveals how nicely you perceive this subject. Bookmarked this web page, will come back for extra articles. You, my pal, ROCK! I found simply the information I already searched all over the place and simply couldn't come across. What a perfect web-site. website tips

    ReplyDelete
  4. Hey there! Nice stuff, please keep us posted when you post again something like that! top brand agencies

    ReplyDelete

Post a Comment

Popular posts from this blog

MySQL Connection

Connection with MySQL Database Before accessing database, you must create a connection to the database Syntax: mysql_connect(servername,username,password); where, servername specifies the server to connect to. Default value is “localhost” username specifies the username to log in with. Default value is the name of the user that owns the server process. To connect offline we use username “root”. password specifies the password to log in with. Default is “” Code : Creating connection to the database and selecting the required database <?php $con = mysql_connect(“localhost”,”root”,”"); if (!$con) { die(‘Could not connect: ‘ . mysql_error()); } else{ mysql_select_db(“test”, $con) }; ?> Here, we have store connection in a variable called $con and trap error using die function. Closing connection The connection will be closed automatically when the script ends. To close the connection before, use the mysql_close() function: <?php $con = mysql_conne...

Type Juggling and Type Casting

Type Juggling: PHP does not require (or support) explicit type definition in variable declaration; a variable's type is determined by the context in which the variable is used. That is to say, if a string value is assigned to variable $var, $var becomes a string. If an integer value is then assigned to $var, it becomes an integer.

Doctype Defination

A Document Type Declaration, or DOCTYPE, is an instruction that associates a particular SGML or XML document (for example, a webpage) with a Document Type Definition (DTD). Syntax The general syntax for a document type declaration is: <!DOCTYPE root-element PUBLIC "FPI" ["URI"] [ <!-- internal subset declarations --> ]>