Pseudo-classes for Form Element

CSS3 introduced some new pseudo-classes for form elements. In this video tutorial we’ll be looking at these 3 pseudo-classes:
:required
:valid
:invalid

required-fields-css3-html5

HTML file
index.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
< !DOCTYPE HTML>
<html>
<head>
<title>CSS pseudo-classes for form elements</title>
<meta charset="utf-8"/>
<link href="myStyle.css" rel="stylesheet"/>
</head>
<body>
 
<form>
Text: <input type="text" required/><br />
Email: <input type="email" placeholder="[email protected]"/><br />
<input type="submit" value="done!"/>
</form>
 
</body>
</html>

Here we have attached a stylesheet where we write css3 form element pseudo-class definition. Here we also take 2 input fields of type text and email respectively. We also make the text field as required. Also add a placeholder to the email input field to provide hint to the user.

CSS file
myStyle.css

1
2
3
4
5
6
7
8
9
10
11
input:required {
background-color: yellow;
}
 
input:valid {
background-color: lightblue;
}
 
input:invalid {
background-color: red;
}

Here the fields which has been specified as required will get a background-color of yellow. valid entries will have a lightblue input field background color, and invalid entry input fields background turns red color.

CSS3 pseudo-classes For Form Element: HTML5


[youtube https://www.youtube.com/watch?v=Yw5s0G1uQoA]

YouTube Link: https://www.youtube.com/watch?v=Yw5s0G1uQoA [Watch the Video In Full Screen.]



Note:
CSS3 introduces new form elements like email, number, date etc ..all these fields validate themselves. We need not write lengthy JavaScript code to make small validations – like, checking if the user entered numeric value in the input field marked as age. Since age input field will have a numeric input type, if the user enters any string, we can let the user know about the wrong entry by making use of these css3 introduced pseudo-classes.

Also note that, if you try to submit the form without filling the required fields, you’ll get a little tool tip like message interface, telling you to fill the form field.

HTML5 and CSS3 Video Tutorial List

Here we list all the HTML5 and CSS3 video tutorials ..all these video tutorials are 3 or 5 or 10 minutes in length and you can go through them very quickly. Learning along with me while I teach is the best way to learn. You can ask your questions/doubts in the comment section of respective tutorial page/post.

HTML5-css3-sticker-technotip

If you’re thinking of HTML7, then my advice would be to first learn HTML5 – this would surly be a basement for upcoming improvements. By learning HTML5, you’ll be ahead of your competition.

Please bookmark this page, share on social sites, let your friends know about our video tutorials – this way you’ll be helping us in our good cause of helping people!

This page will be updated with up coming HTML5 and CSS3 lessons ..stay subscribed

Enter your email address:

    Geolocation API

  1. Geolocation API – Success Handler: HTML5
  2. Geolocation API – Error Handle: HTML5
  3. Google Maps Integration: HTML5
  4. Adding Pin/Marker To Google Map: HTML5
  5. Add Popup message To Google Map Pin: HTML5
  6. Realtime Location Tracking – Google Maps: HTML5

    Canvas

  1. Canvas Basics: HTML5
  2. Draw Rectangle: HTML5 Canvas
  3. Canvas State: HTML5
  4. Canvas clearRect: HTML5
  5. Canvas Lines and Paths: HTML5
  6. Line Ending In Canvas: HTML5
  7. Line Joining In Canvas: HTML5
  8. Draw Arcs/Circle with Canvas: HTML5
  9. Bezier Curve In Canvas: HTML5
  10. Quadratic Curve In Canvas: HTML5
  11. Draw Text on Canvas: HTML5
  12. Shadow Effect on Canvas: HTML5
  13. Canvas Image Patterns: HTML5
  14. Canvas Element Pattern: HTML5
  15. Linear Gradients in Canvas: HTML5
  16. Radial Gradients in Canvas: HTML5
  17. Clipping Paths in Canvas: HTML5
  18. drawImage() in Canvas: HTML5
  19. Translate Transformation in Canvas: HTML5
  20. Scale Transformation in Canvas: HTML5
  21. Rotate Transformation in Canvas: HTML5
  22. Custom Transformation in Canvas: HTML5
  23. globalAlpha and RGBa in Canvas: HTML5
  24. Compositing Methods in Canvas: HTML5
  25. Accessing Raw Pixel Data in Canvas: HTML5
  26. Image Gallery using Canvas: HTML5
  27. Simple Animation using Canvas: HTML5

    HTML5 Web Forms

  1. Pseudo-classes for Form Element
  2. autofocus Attribute of Form Field: HTML5
  3. autocomplete Attribute of Form Field: HTML5
  4. Suggested Entries Using datalist Element: HTML5
  5. Dynamic Suggested List: HTML5 + jQuery + PHP + MySQL
  6. placeholder Attribute of Form Field: HTML5
  7. pattern and title Attribute of Form Field: HTML5
  8. require attribute: HTML5
  9. Form novalidate attribute: HTML5
  10. Text Selection API: HTML5
  11. Form Input Type – search: HTML5
  12. Email Input Type: HTML5
  13. URL Input Type: HTML5
  14. Tel Input Type: HTML5
  15. number Input Type: HTML5
  16. range Input Type: HTML5
  17. date time Input Type: HTML5
  18. color Input Type: HTML5
  19. progress Element: HTML5
  20. Download Attribute: HTML5

..more videos will be added soon, stay subscribed

Enter your email address:

UPDATE / EDIT Records In Database Table: PHP & MySQL

Video tutorial demonstrates updating / editing of data / records from the database table and displaying it on the browser.

First look at these short videos:
Connect to the database
Simple / basic insertion operation
Insertion of Records into Database using Forms: PHP & MySQL (important)
SELECT / LIST Records From Database Table: PHP & MySQL

Source Code: SELECTING and Displaying Data

index.php

<?php

include_once('db.php');
 
if(isset($_POST['name']))
{
  $name = $_POST['name'];
 
  if(mysql_query("INSERT INTO apple VALUES('','$name')"))
echo "Successful Insertion!";
  else
echo "Please try again";
}
 
 
$res = mysql_query("SELECT * FROM apple");
 
 
?>
 
<form action="." method="POST">
Name: <input type="text" name="name"/><br />
<input type="submit" value=" Enter "/>
</form>
 
<h1>List of companies ..</h1>
< ?php
while( $row = mysql_fetch_array($res) )
  echo "$row[id]. $row[name] 
                <a href='edit.php?edit=$row[id]'>edit<br />";
?>

Video Tutorial: UPDATE / EDIT Records In Database Table: PHP & MySQL


[youtube https://www.youtube.com/watch?v=Hw1MwUlekeo]

https://www.youtube.com/watch?v=Hw1MwUlekeo [Watch the Video In Full Screen.]


Source Code: Updating / Editing Data / Records In The Database Table

edit.php

<?php
include_once('db.php');
 
if( isset($_GET['edit']) )
{
$id = $_GET['edit'];
$res= mysql_query("SELECT * FROM apple WHERE id='$id'");
$row= mysql_fetch_array($res);
}
 
if( isset($_POST['newName']) )
{
$newName = $_POST['newName'];
$id   = $_POST['id'];
$sql     = "UPDATE apple SET name='$newName' WHERE id='$id'";
$res  = mysql_query($sql) 
                                    or die("Could not update".mysql_error());
echo "<meta http-equiv='refresh' content='0;url=index.php'>";
}
 
?>

<form action="edit.php" method="POST">
Name: <input type="text" name="newName" value="<?php echo $row[1]; ?/>"><br />
<input type="hidden" name="id" value="<?php echo $row[0]; ?/>">
<input type="submit" value=" Update "/>
</form>

meta tag used to redirect to other page..

<meta http-equiv='refresh' content='0;url=index.php'>

MySQL Query

mysql> UPDATE apple SET name='newName' WHERE id='session_id';

Security Issue:
Make sure not to allow people to explicitly pass random id’s and retrieve and edit/update other’s data. To solve this issue, you can save the id of the logged in user in a session variable and instead of passing id to edit.php we can directly use the id stored in our session variable.
This would solve the issue.

Output: After Updating the records:

  1. Google USA
  2. Apple USA
  3. Microsoft USA
  4. Oracle USA
  5. Technotip IN

Video’s To Watch:
GET method in action
Post method in action
session variable basics
User login and session