AJAX Call with basic Form Validation

Hi Friends,

Today I have learned about AJAX. It is Asynchronous JavaScript And XML. Using Ajax you can pass the values without page refreshing. Here with  gave an example code for your reference. It is very basic level only.

validation.html


<!DOCTYPE html>
<html>
<head>
<title>Basic Form Validation</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<!--Style for validate file -->

<link rel="stylesheet" content="type/css" href="css/style.css">
<link rel="stylesheet" content="type/css" href="css/bootstrap.min.css">
</head>
<body class="form-bg">

<div class="container">
<div class="row">
<div class="col-md-12 form_val">
<h2 class="val_title">Basic Form Validation</h2>

<div class="form-group col-md-offset-4 col-md-4 col-md-offset-4">
<label for="userid">User Name</label>
<input name="userid" class="form-control" id="usr" type="text">
<div id="msg1" style="color:#FF0000"></div>
</div>

<div class="form-group col-md-offset-4 col-md-4 col-md-offset-4">
<label for="email">Email</label>
<input name="email" class="form-control" id="email" type="text">
<div id="msg2" style="color:#FF0000"></div>
</div>

<div class="form-group col-md-offset-4 col-md-4 col-md-offset-4">
<label for="mobile">Mobile Number</label>
<input name="mobile" class="form-control" id="mobile" type="text">
<div id="msg3" style="color: #FF0000"></div>
</div>


<div class="form-group col-md-offset-4 col-md-4 col-md-offset-4">
<button type="submit" onClick="formvalidate()" class="btn btn-success">Submit</button>
</div>
</div>
</div>
</div>
<!--Script for validate file--->

<script type="text/javascript" src="js/my-script.js"></script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>

</body>
</html>

 

style.css


/*** Style for form validation start**/

.form-bg {
background: #fff;
}
.form_val {
top: 0;
margin-top: 10%;
border: 2px solid #fff;
padding: 100px;
background: #ccc;
}
.val_title {
text-align: center;
font-family: "Montserrat-Regular";
padding-bottom: 20px;
}

/*** Style for form validation end**/

&nbsp;

my-script.js


/****Form validation start******/

function formvalidate() {
var str=true;
document.getElementById("msg1").innerHTML="";
document.getElementById("msg2").innerHTML="";
document.getElementById("msg3").innerHTML="";

if(document.getElementById("usr").value=='') {
document.getElementById("msg1").innerHTML="*Please Enter User Name";
str=false;
}

if(document.getElementById("email").value=='') {
document.getElementById("msg2").innerHTML="*Please Enter Your Email Id";
str=false;
}
else {
var validate_char= /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
if(!document.getElementById("email").value.match(validate_char)) {
document.getElementById("msg2").innerHTML="*Please Enter Valid Email ID";
str=false;
}
}

if(document.getElementById("mobile").value=='') {
document.getElementById('msg3').innerHTML="*Please Enter Your Mobile Number";
str=false;
}
else {
var mob_val = /^(\+\d{1,3}[- ]?)?\d{10}$/;
if(!document.getElementById("mobile").value.match(mob_val)) {
document.getElementById("msg3").innerHTML="*Please Enter Valid Mobile Number";
str=false;
}
}


/***Ajax part start***/

if(str == true) {
var userName = $("#usr").val();
var email = $("#email").val();
var mobile = $("#mobile").val();

$.ajax ({
url: "a_validation.php",
type: "post",
data: {
a_validation: "a_validation",
usr: userName,
email: email,
mobile: mobile

},
success: function() {
alert("Form Value is Soterd Successfully");
}
});
}

/***Ajax part end***/
}

/****Form validation end******/



Screenshot 1:

test1

Screenshot 2:

test2

Note : Screenshot 2 shows inspect element with network option through ajax value passing in the bottom of Header named as Form Data. (userName, email, Mobile Number)

 

 

 

 

 

 

 

Posted in Projects | Tagged , , | Leave a comment

Basic Search Button Design

Hi Friends,

Today i have created Basic Search Button Design. Once you hover on the search icon, it will expanded with text bar. It is very easy design.

Here with i have mentioned files details.

  1. search-button.html :


<!DOCTYPE html>
<html lang="en">
<head>
<title>Search Button Design</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<!--Style for upload file -->
<link rel="stylesheet" content="type/css" href="css/style.css">
<link rel="stylesheet" content="type/css" href="css/bootstrap.min.css">

<!--Script for upload file--->

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
</head>

<body class="search-bg">

<!--Search button start---->

<div class="search_over col-md-offset-4 col-md-4 col-md-offset-4">
<div class="search_title">
Basic Search Button Design
</div>
<div class="search_button col-md-offset-2">
<span class="search_main">
<input type="search" id="search" placeholder="Search..." />
<img src="img/searchicon.png" class="ser_icon">
</span>
</div>
</div>

<!--Search button end---->

</body>
</html>

2. style.css


/*******************

 Author: Yuvaraj
 Designation: UI Developer
 Email: yuvaa45@gmail.com
 website: http://yuvaraj.slashprog.com/
 File Name: style.css
 
***********************/

/** Style for search button start***/

body.search-bg {background: #ccc;}
.search_main {
width: 300px;
vertical-align: middle;
white-space: nowrap;
position: relative;
}
.search_main input#search {
width: 30px;
height: 30px;
background: transparent;
border: none;
font-size: 16px;
float: left;
color: #262626;
padding-left: 5px;
border-radius: 0px;
color: #fff;
transition: width .55s ease;
}
.search_main input#search:focus,
.search_main input#search:active {
outline:none;
width: 300px;
border: none;
border-bottom: 1px solid #ccc;
color: #000;
}
.search_main:hover input#search {
width: 300px;
border: none;
border-bottom: 1px solid #ccc;
color: #000;
}
.ser_icon {
position: absolute;
right: 0;
margin-right: 5px;
margin-top: 5px;
}
.search_title {
padding: 50px;
font-size: 18px;
font-family: "Montserrat-Regular";
text-align: center;
}
.search_over {
padding: 100px;
border: 2px solid #ccc;
margin-top: 20px;
background: #fff;
border-radius: 20px;
}

/** Style for search button end***/

Image :

searchicon

Screen Shot : 1

basic-search

 

Screen Shot : 2

 

basic-search-one

 

Note : Once you can click on this image you can clear view of this screen shots.

 

 

 

 

Posted in Projects | Tagged , , , | Comments Off on Basic Search Button Design

File Upload Button Design

Hi Friends,

After a long while back to form. Hope all are doing well.

Today i have created File Upload Button using Bootstrap and Js.

Here with you have upload file formats like PDF, doc and docx only.

This file upload design is fully responsive. You can use these design for all devices like mobile, tab, laptop, desktop, large desktops.

  1.  index.html file :

<!DOCTYPE html>
<html>
<head>
<title>File Upload</title>
<!--Style for upload file -->
<link rel="stylesheet" content="type/css" href="css/style.css">
<link rel="stylesheet" content="type/css" href="css/bootstrap.min.css">

<!--Script for upload file--->

<script type="text/javascript" src="js/jquery.min.js"></script> 
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/my-script.js"></script> 
</head>
<body class="upload_btn_model">

<!---Upload button structure start----->
<div class="upload_btn">
 <div class="container">
 <div class="col-md-offset-4 col-md-4 col-md-offset-4 upload_button">
 <div class="apply">Apply Now</div>
 <p class="up_title">This is Styled Upload Button</p>
 
 <form>
 
 <div class="form-group">
 <input type="text" class="form-control" placeholder="Enter Your Name" id="usr">
 </div>
 
 <div class="form-group">
 <input type="email" class="form-control" placeholder="Enter Your Email" id="email">
 </div>
 
 <div class="upl_border">
 <p class="up_txt">Upload Your File Here</p>
 
 <p class="upload_txt">
 [ Use only .doc or pdf format ]
 </p>
 
 <div class="text-center">
 <label class="btn btn-default upl_btn" for="my_file"><img src="img/resume-upload.png" 
 alt="upload_button" width="50" height="50" ></label>
 </div>
 
 <input type="file" id="my_file" name="file_upload" accept=".pdf,.doc,.docx" 
 style="display: none">
 
 <p class="file_name"></p>
 </div>
 
 </form>
 
 <p class="fot-txt">All the best for your success!</p>
 </div>
 </div>
</div>

<!---Upload button structure end----->

</body>
</html>

2.  style.css file :


/*******************

Author: Yuvaraj
Designation: UI Developer
Email: yuvaa45@gmail.com
website: http://yuvaraj.slashprog.com/
File Name: style.css

***********************/

/** Font file**/
@font-face {
font-family: "Montserrat-Regular";
src: url("./fonts/Montserrat-Regular.otf");
}
@font-face {
font-family: "Montserrat-Light";
src: url("./fonts/Montserrat-Light.otf");
}
@font-face {
font-family: "Montserrat-Bold";
src: url("./fonts/Montserrat-Bold");
}
@font-face {
font-family: "Montserrat-SemiBold";
src: url("./fonts/Montserrat-SemiBold.otf");
}
@font-face {
font-family: "Montserrat-Thin";
src: url("./fonts/Montserrat-Thin.otf");
}

/** Style for file upload start***/

.upload_btn_model { 
background: #ccc;
 }
.upload_btn {
 padding: 40px 0px;
 }
.up_title {
 padding-top: 30px; 
 font-family: "Montserrat-Light"; 
 font-size: 18px; 
 text-align: center; 
 }
.up_txt {
 font-family: "Montserrat-Light"; 
 font-size: 16px; 
 text-align: center; 
 padding-top: 20px;
 }
.upload_txt {
 text-align: center; 
 font-family: "Montserrat-Light"
 }
.upload_button {
 background: #fff; 
 padding: 50px;
 }
.upl_border {
 border: 4px dashed #404040; 
 padding-bottom: 30px;
 }
.apply {
 font-size: 30px; 
 font-family: "Montserrat-Regular"; 
 text-align: center;
 }
.file_name {
 text-align: center; 
 font-family: "Montserrat-Light"
 }
.fot-txt {
 text-align: center;
 font-family: "Montserrat-Regular";
 font-size: 20px;
 padding-top: 20px;
 }

/** Style for file upload end***/

3. my-script.js

[JS File] :


/**************************************************************

Author: Yuvaraj
Designation : UI Developer
website: http://yuvaraj.slashprog.com/
File Name: my-script.js

***************************************************************/

/***Script for file upload start***/

$(document).ready(function() {
$('input[type="file"]#my_file').on('change', function() {
var fileName = $(this).val().split('\\').pop();
$(".file_name").text(fileName);
})
})

/***Script for file upload end***/

Images : 

resume-upload

Screen Shot Of File Upload Page : 

Test Document

 

 

 

 

Posted in Projects | Tagged , , , | Comments Off on File Upload Button Design

Basic Form Validation

Hi Friends,

Today I have created Basic Form Validation with responsive design using bootstrap and js .  Here with three fields are there. User Name , Email and Mobile number.

When you submit the form without giving input value it will raises an error message its called as alert.

I have shared file details here :

  1. validation.html


<!DOCTYPE html>
<html>
<head>
<title>Basic Form Validation</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<!--Style for validate file -->
<link rel="stylesheet" content="type/css" href="css/style.css">
<link rel="stylesheet" content="type/css" href="css/bootstrap.min.css">

<!--Script for validate file--->

<script type="text/javascript" src="js/jquery.min.js"></script> 
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/my-script.js"></script> 
</head>
<body class="form-bg">

<div class="container">
 <div class="row">
 <div class="col-md-12 form_val">
 <h2 class="val_title">Basic Form Validation</h2>
 <form name="frm" action="" method="post" onSubmit="return formvalidate()">
 
 <div class="form-group col-md-offset-4 col-md-4 col-md-offset-4">
 <label for="userid">User Name</label>
 <input name="userid" class="form-control" id="usr" type="text">
 <div id="msg1" style="color:#FF0000"></div>
 </div> 
 
 <div class="form-group col-md-offset-4 col-md-4 col-md-offset-4">
 <label for="email">Email</label>
 <input name="email" class="form-control" id="email" type="text">
 <div id="msg2" style="color:#FF0000"></div>
 </div>
 
 <div class="form-group col-md-offset-4 col-md-4 col-md-offset-4">
 <label for="mobile">Mobile Number</label>
 <input name="mobile" class="form-control" id="mobile" type="text">
 <div id="msg3" style="color: #FF0000"></div>
 </div>
 
 
 <div class="form-group col-md-offset-4 col-md-4 col-md-offset-4">
 <button type="submit" class="btn btn-success">Submit</button>
 </div>
 
 </form>
 </div>
 </div>
</div> 

</body>
</html>

 

2. style.css :


/*** Style for form validation start**/

.form-bg {
background: #fff;
}
.form_val {
top: 0;
margin-top: 10%;
border: 2px solid #fff;
padding: 100px;
background: #ccc;
}
.val_title {
text-align: center;
font-family: "Montserrat-Regular";
padding-bottom: 20px;
}

/*** Style for form validation end**/

 

3. my-script.js


/****Form validation start******/

function formvalidate() {
var str=true;
document.getElementById("msg1").innerHTML="";
document.getElementById("msg2").innerHTML="";
document.getElementById("msg3").innerHTML="";

if(document.frm.userid.value=='') {
document.getElementById("msg1").innerHTML="*Please Enter User Name";
str=false;
}

if(document.frm.email.value=='') {
document.getElementById("msg2").innerHTML="*Please Enter Your Email Id";
str=false;
}
else {
var validate_char= /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
if(!document.frm.email.value.match(validate_char)) {
document.getElementById("msg2").innerHTML="*Please Enter Valid Email ID";
str=false;
}
}

if(document.frm.mobile.value=='') {
document.getElementById('msg3').innerHTML="*Please Enter Your Mobile Number";
str=false;
}
else {
var mob_val = /^(\+\d{1,3}[- ]?)?\d{10}$/;
if(!document.frm.mobile.value.match(mob_val)) {
document.getElementById("msg3").innerHTML="*Please Enter Valid Mobile Number";
str=false;
}
}
return str;
}

/****Form validation end******/

Note: Suppose external my-script.js is not working means you could past the js code inside            of body tag (validation.html). Now it will be working fine.

4. Screen Shots :

Basic Form Validation

 

Basic Form Validation (1)

 

 

 

 

 

 

Posted in Projects | Tagged , , , , , | Comments Off on Basic Form Validation

PHP Variables And Print Statements

Greetings,

Today i have learned PHP Variables, Print or Echo Statements. The variables are used to store the values. The Echo statement is used to print the output.

PHP VARIABLES :

  • The PHP variables are starts with $ sign and  followed by the variable name.
  • The variables are must starts with $ sign or Underscore.
  • But it should not starts with number.
  • The variable contain only alpha-numeric characters (A-z, 0-9 and _) .
  • Variable names are case-sensitivity.

Example:

<?php

$first_value = 20;
$second_value = -30;
$third_value = "Hello Yuvaraj";

echo "$first_value <br>";
echo "$second_value <br>";
echo "$third_value <br>";

?>

OUTPUT :

20 
-30 
Hello Yuvaraj

Note : Here with $first_value, $second_value, $third_value  is  variables.  Echo is an output variable, it is used to print or display the output on screen.

PHP is Loosely Typed Language :

In PHP we didn’t mention which data type is the variable. Depending on variable PHP will automatically converted it data types.

PHP VARIABLES :

PHP variables declared in anywhere in the script.

The variables has three type of scopes :

  1. Static
  2. Global
  3. Local

GLOBAL VARIABLE :

A variable declared in outside function of global scope and can only accessed by outside a function is called global variable.

Example :

<?php

$name = "Yuvaraj";  // global scope 

function testGlobal() {
 echo "This is inside variabel : $name "; // inside a function

 }

testGlobal();  // outside a function 

echo "This is outside variable : $name ";

?>

OUTPUT : 

This is inside variabel : 

This is outside variable : Yuvaraj

LOCAL VARIABLE :

A variable declared inside a function of local scope  and can only accessed inside of function is called local variable.

Example :

<?php

function testGlobal() {
 $name = "Yuvaraj";                        // local scope 
 echo "This is inside variabel : $name "; // inside a function

 }

testGlobal();  // outside a function 

echo "This is outside variable : $name ";

?>

OUTPUT :

This is inside variabel : Yuvaraj 
This is outside variable :

GLOBAL KEYWORD FOR PHP :

The global keyword is used to access the global variable inside the function.

Example :

<?php
$fname = "Yuvaraj";
$lname = "Yuvaa";
function testGlobal() {
  global $fname, $lname;
 }
testGlobal();
echo "This is inside function for global variabel : $fname $lname ";

?>

OUTPUT :

This is inside function global variabel : Yuvaraj Yuvaa

STATIC KEYWORD FOR PHP :

When function is executed or completed, all of its variables are deleted. But some time we need local variable to use other purpose at the time we can use static variable.

Example :

<?php 

function myStatic() {
 static $number = 0;
 echo $number;
 $number++;
 }

myStatic();
echo "<br>";
myStatic();
echo "<br>";
myStatic();
echo "<br>";

OUTPUT :

?>
0
1
2

PHP ECHO or PRINT STATEMENTS :

The PHP has getting output through two ways,

  1. echo
  2. print

Here with “echo” has no return value but “print” has return value of 1 . Echo can take multiple parameters, while print can take one argument. Echo is faster than Print.

Example :

<?php 

   echo "This test case for echo <br>";
   print "This is test case for print";

?>

OUTPUT :

This test case for echo 
This is test case for print

Example For Displaying Variables with Echo :

<?php 

$name = "Yuvaraj";
$x = 2;
$y = 3;

echo "my name is $name <br>";
echo $x + $y;

?>

OUTPUT :

my name is Yuvaraj 
5

 

 

 

Posted in PHP | Tagged , , , , , , | Comments Off on PHP Variables And Print Statements