jQuery Form Validation Example

jQuery Form Validation Example:

We used to validate the form using javascript and there we have to write our own logics to validate the email, phone number and mandatory fields etc….

But now jquery validate plugin is available for ease of form validations.

Include the below scripts:

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.js"></script>

Form need to be validated:

<form method="post" action="signup.php?retrun=http://www.gururecharge.chudar.com/terms.php"  id="validate_form" name="validate_form">
<div class="divmain" style="  float:left; margin-left:45px; border-right:thin ridge; padding-right:30px;  ">
  <div style="border-bottom:#CCC  solid 1px;"></div>
 <br />
  <div class="divbox1">
    <div class="divbox11">
   <div style="padding:12px 0px 6px 0px;">Enter your full name</div>
   <input type="text" name="usr_name" id="usr_name">
     <div id="disp3"></div>
<div style="padding-bottom:6px;">Enter your Mobile Number</div>
<div class="countryCode">
<input type="text" name="mobileno" id="mobileno" maxlength="10">
<span style="color:#F00;display:none;" id="rvEVMN">Please insert Valid Mobile no</span>
</div>	
<div id="disp"></div>
<div style="padding:12px 0px 6px 0px;">Enter your Email ID</div>
     <input type="text" name="email" id="email">
     <div id="disp1"></div>
 <div style="padding:12px 0px 6px 0px;">Create your Password</div>
     <input type="password" name="password" id="password">
     <div style="clear:both;"></div>
    <div align="right" style="padding-right:90px; padding-top:10px; padding-bottom:10px;">
    </div>
    <div class="btn-spinner" alt="Proceed to Recharge"><div class="spinner hidden"></div>
    <input type="submit" class="btn proceed active" data-express-text="Recharge Now" data-soft-block-text="Proceed anyway" data-default-text="Proceed" name="Proceed" value="Create Account" alt="Proceed to Recharge" ></div>   
    </div>    
  </div>
  <div style="clear:both;"></div>
</div>
</form>

Script to validate the form:

<script>
  $(function() {	  
  // form name
	$("#validate_form").validate({    
		rules: {
			mobileno: 
			{
			required: true,
			number: true,
			minlength: 10,
			maxlength:10,
			},
            email:  {
				required: true,
				email: true,
			},
			password: 
			{
				required: true,
				minlength: 6,
			},
			usr_name:
				{
				required: true,
			},
			},
        // Specify the validation error messages
		messages: {
			mobileno: "Mobile no is mandatory",
			email:  "Email is mandatory",
            password:  "Password is mandatory",
            usr_name:  "Name is mandatory",
        },
        submitHandler: function(form) {
         if($("#mobileno").val() > 0) {   form.submit(); } else {
	document.getElementById('rvEVMN').style.display='inline';		 return false;
			 }
        }
    });
  });
  </script>

Complete source code:

 <html>
<head>
<title>
jQuery Form validation Example
</title>
</head>
<body>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.js"></script>
<script>
  $(function() {	  
  // form name
	$("#validate_form").validate({    
		rules: {
			mobileno: 
			{
			required: true,
			number: true,
			minlength: 10,
			maxlength:10,
			},
            email:  {
				required: true,
				email: true,
			},
			password: 
			{
				required: true,
				minlength: 6,
			},
			usr_name:
				{
				required: true,
			},
			},
        // Specify the validation error messages
		messages: {
			mobileno: "Mobile no is mandatory",
			email:  "Email is mandatory",
            password:  "Password is mandatory",
            usr_name:  "Name is mandatory",
        },
        submitHandler: function(form) {
         if($("#mobileno").val() > 0) {   form.submit(); } else {
	document.getElementById('rvEVMN').style.display='inline';		 return false;
			 }
        }
    });
  });
  </script>
<form method="post" action="signup.php?retrun=http://www.gururecharge.chudar.com/terms.php"  id="validate_form" name="validate_form">
<div class="divmain" style="  float:left; margin-left:45px; border-right:thin ridge; padding-right:30px;  ">
  <div style="border-bottom:#CCC  solid 1px;"></div>
 <br />
  <div class="divbox1">
    <div class="divbox11">
   <div style="padding:12px 0px 6px 0px;">Enter your full name</div>
   <input type="text" name="usr_name" id="usr_name">
     <div id="disp3"></div>
<div style="padding-bottom:6px;">Enter your Mobile Number</div>
<div class="countryCode">
<input type="text" name="mobileno" id="mobileno" maxlength="10">
<span style="color:#F00;display:none;" id="rvEVMN">Please insert Valid Mobile no</span>
</div>	
<div id="disp"></div>
<div style="padding:12px 0px 6px 0px;">Enter your Email ID</div>
     <input type="text" name="email" id="email">
     <div id="disp1"></div>
 <div style="padding:12px 0px 6px 0px;">Create your Password</div>
     <input type="password" name="password" id="password">
     <div style="clear:both;"></div>
    <div align="right" style="padding-right:90px; padding-top:10px; padding-bottom:10px;">
    </div>
    <div class="btn-spinner" alt="Proceed to Recharge"><div class="spinner hidden"></div>
    <input type="submit" class="btn proceed active" data-express-text="Recharge Now" data-soft-block-text="Proceed anyway" data-default-text="Proceed" name="Proceed" value="Create Account" alt="Proceed to Recharge" ></div>   
    </div>    
  </div>
  <div style="clear:both;"></div>
</div>
</form>
</body>
</html>

This will work this way,
Form to validate using jQuery

And validation worked this way,
validated form

Download Source code:

jQuery Form Validation Example

Recommended jQuery Books:

How to use property file in php ?

How to use property file in php ?

What is Property file ?
Property file in php will have the .ini extension. which will be used generally for the constant informations like website_url, filepaths and key, value mappings etc.

Extension:
Its a .ini extension.

Sample Property file:

prop.ini:

Idea=12
Airtel=2
Aircel=1

(or)

Idea=12;
Airtel=2;
Aircel=1;

PHP Code to get the prop(ini file) values by its key:

<?php
$ini_array = parse_ini_file("prop.ini");
$propKey = 'Idea';
echo $ini_array[$propKey];
?>

Output:
12

Download Source code:
Php Property File Source code

Please feel free to post your queries/comments…..

Php Recommended Books:

Removing Featured Image from post and search result wordpress [Solved]

Removing Featured Image from post and search result wordpress:

1. Comment the below snippet from the single.php (in some themes file names may vary. (vantage theme -> content-single.php))

<!-- <?php if( has_post_thumbnail() && siteorigin_setting('blog_featured_image') ): ?>
<div class="entry-thumbnail"><?php the_post_thumbnail( is_active_sidebar('sidebar-1') ? 'post-thumbnail' : 'vantage-thumbnail-no-sidebar' ) ?></div>
<?php endif; ?>
-->

If you comment the above snippet, it will remove the thumbnail or featured image only from the post. But still it will exist in the post search page.

2. Comment the below snippet from the search.php (in some themes file name may vary)

Search under entry-header section then comment the below lines, then it will not be displayed even in post search page.

<!--  <?php if( has_post_thumbnail() && siteorigin_setting('blog_featured_image_type') == 'large' ): ?>
<div class="entry-thumbnail">
<a href="<?php the_permalink() ?>"><?php the_post_thumbnail( is_active_sidebar('sidebar-1') ? 'post-thumbnail' : 'vantage-thumbnail-no-sidebar' ) ?></a>
</div>
<?php endif; ?>
-->

Feel free to comment/provide some other solutions….

PHP Recommended Books:

How to use conditional breakpoint in eclipse (step by step)

We can say no developers in the world who developing without debugging his/her code. We have lot of debugging options to make use the debugging option more effectively.

Here we are going to see how we can debug with conditional breakpoints.
Step 1:
Below is the very simple program to explain the conditional breakpoint,

package in.javadomain;
public class ConditionalBreakpoint {
	public static void main(String[] args) {
		boolean value = false;
		value=true;
		System.out.println("Debug, if condition given in the breakpoint condition satisfies ");
	}

}

Step 2:
Put the breakpoint in the sysout line of the above program.

Step 3:
Right click on the breakpoint and click breakpoint properties (or) control+double click on the breakpoint, then click the Breakpoint properties -> Enable the Conditional checkbox -> click suspend when true radio button.
Then add the condition,
setting breakpoint

Now Run as debug and see the output for both the conditions (value==false and value==true) below,

when value==true
conditional breakpoint

when value==false
conditional_breakpoint_false

Note:
After changing the breakpoint conditions, ensure you have saved it.

Recommended Java Books:

Main Method auto generation in java Eclipse example

As we know main method is first method java begins its execution. That main method we can generate using two ways in eclipse
Way 1:

While creating the class, we can enable the “public static main method(String[] args) checkbox”,

AutoGenCreate

Way 2:

If we have created the class without enabling the checkbox, then no need to delete and create it again. We can simply create simply typing main with ctrl+shift.

AutoGenCtrlShift

Recommended Books:

Java With MySQL Insert Example

Download the users_test table:
Users_test table – Mysql download

Loading the Mysql connection:

	public Connection LoadDriver() {
		Connection connection = null;
		try {
			// Driver Name
			String mySQLDriver = "org.gjt.mm.mysql.Driver";
			// Path/database name [here guru is the database name]
			String url = "jdbc:mysql://localhost:3306/guru";
			Class.forName(mySQLDriver);
			// User name and password
			connection = DriverManager.getConnection(url, "root", "pass123");

		} catch (Exception exception) {
			System.err.println("Exception! ");
			System.err.println(exception.getMessage());
		}
		return connection;
	}

Fetching the records: [Select]

	public void insertUsers(Connection conn, String email,String full_name,String mobile,String pass,String access){
		System.out.println("Insert started!");
		String query = " insert into users_test (mobile,email,pass,full_name, access) values (?, ?, ?, ?,?)";
		PreparedStatement preparedStmt;
		try {
			preparedStmt = conn.prepareStatement(query);
			preparedStmt.setString(1, mobile);
			preparedStmt.setString(2, email);
			preparedStmt.setString(3, pass);
			preparedStmt.setString(4, full_name);
			preparedStmt.setString(5, access);
			preparedStmt.execute();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		System.out.println("Insertion Done!");
	}

Java with Mysql Insert Full Program:

package in.javadomain;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * @author Naveen class to connect java with mysql and fetching mysql records
 *         using java
 */
public class JavaMySQL {
	/**
	 * Main method first get the mysql connection then it will fetch the records
	 */
	public static void main(String[] args) {
		String email = "me@javadomain.in";
		String full_name = "naveenkumar";
		String mobile = "9597470873";
		String pass = "testpass";
		String access = "1";
		JavaMySQL javaMySQL = new JavaMySQL();
		// Getting the mysql Connection
		Connection conn = javaMySQL.LoadDriver();
		// Fetching the mysql table records
		javaMySQL.insertUsers(conn, email, full_name, mobile, pass, access);
	}

	/**
	 * Loads the mysql connection with the given username, password, database
	 * and mysql jar driver
	 * 
	 * @return Connection
	 */
	public Connection LoadDriver() {
		Connection connection = null;
		try {
			// Driver Name
			String mySQLDriver = "org.gjt.mm.mysql.Driver";
			// Path/database name [here guru is the database name]
			String url = "jdbc:mysql://localhost:3306/guru";
			Class.forName(mySQLDriver);
			// User name and password
			connection = DriverManager.getConnection(url, "root", "pass123");

		} catch (Exception exception) {
			System.err.println("Exception! ");
			System.err.println(exception.getMessage());
		}
		return connection;
	}

	/**
	 * @param conn
	 * @param email
	 * @param full_name
	 * @param mobile
	 * @param pass
	 * @param access
	 *            all the above params are inserted using the prepared statement
	 */
	public void insertUsers(Connection conn, String email, String full_name,
			String mobile, String pass, String access) {
		System.out.println("Insert started!");
		String query = " insert into users_test (mobile,email,pass,full_name, access) values (?, ?, ?, ?,?)";
		PreparedStatement preparedStmt;
		try {
			preparedStmt = conn.prepareStatement(query);
			preparedStmt.setString(1, mobile);
			preparedStmt.setString(2, email);
			preparedStmt.setString(3, pass);
			preparedStmt.setString(4, full_name);
			preparedStmt.setString(5, access);
			preparedStmt.execute();
		} catch (SQLException e) {
			e.printStackTrace();
		}

		System.out.println("Insertion Done!");
	}

}

Output:

Insert started!
Insertion Done!

Download the Source code:
Java With Mysql Insert

Note:
1. Do not forget to add the mysql java connection jar.
2. Mention the username, password and database name correctly.
3. Mention the column names, column name types and table names correctly.

Java Recommended Books:

Java With MySQL Select Example

Download the users_test table:
Users_test table – Mysql download

Loading the Mysql connection:

	public Connection LoadDriver() {
		Connection connection = null;
		try {
			// Driver Name
			String mySQLDriver = "org.gjt.mm.mysql.Driver";
			// Path/database name [here guru is the database name]
			String url = "jdbc:mysql://localhost:3306/guru";
			Class.forName(mySQLDriver);
			// User name and password
			connection = DriverManager.getConnection(url, "root", "pass123");

		} catch (Exception exception) {
			System.err.println("Exception! ");
			System.err.println(exception.getMessage());
		}
		return connection;
	}

Fetching the records: [Select]

public void getRecords(Connection connection) {
		String query = "SELECT * FROM users_test";
		Statement createStatement;
		try {
			createStatement = connection.createStatement();
			ResultSet resultSet = createStatement.executeQuery(query);
			while (resultSet.next()) {
				String mobile = resultSet.getString("mobile");
				String full_name = resultSet.getString("full_name");
				String email = resultSet.getString("email");
				System.out.format("%s, %s, %s\n", full_name, email, mobile);
			}
			createStatement.close();
		} catch (SQLException sqlException) {
			sqlException.printStackTrace();
		}

	}

Mysql With Select Full Program:

package in.javadomain;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @author Naveen 
 * class to connect java with mysql and fetching mysql records
 *         using java
 */
public class JavaMySQL {
	/**
	 * Main method first get the mysql connection then it will fetch the records
	 */
	public static void main(String[] args) {
		JavaMySQL javaMySQL = new JavaMySQL();
		// Getting the mysql Connection
		Connection conn = javaMySQL.LoadDriver();
		// Fetching the mysql table records
		javaMySQL.getRecords(conn);
	}

	/**
	 * Loads the mysql connection with the given username, password, database
	 * and mysql jar driver
	 * 
	 * @return Connection
	 */
	public Connection LoadDriver() {
		Connection connection = null;
		try {
			// Driver Name
			String mySQLDriver = "org.gjt.mm.mysql.Driver";
			// Path/database name [here guru is the database name]
			String url = "jdbc:mysql://localhost:3306/guru";
			Class.forName(mySQLDriver);
			// User name and password
			connection = DriverManager.getConnection(url, "root", "pass123");

		} catch (Exception exception) {
			System.err.println("Exception! ");
			System.err.println(exception.getMessage());
		}
		return connection;
	}

	/**
	 * @param connection
	 *            to create the mysql connection Records fetched using create
	 *            statement
	 */
	public void getRecords(Connection connection) {
		String query = "SELECT * FROM users_test";
		Statement createStatement;
		try {
			createStatement = connection.createStatement();
			ResultSet resultSet = createStatement.executeQuery(query);
			while (resultSet.next()) {
				String mobile = resultSet.getString("mobile");
				String full_name = resultSet.getString("full_name");
				String email = resultSet.getString("email");
				System.out.format("%s, %s, %s\n", full_name, email, mobile);
			}
			createStatement.close();
		} catch (SQLException sqlException) {
			sqlException.printStackTrace();
		}

	}
}

Output:

Hems, Hems@Hems.com, 7777777777
Aravind, aravind@aravind.com, 7777788888
Chudar, chudar@chudar.com, 8888888888
Naveen, naveen@naveen.com, 9999999999

Download the Source code:
Java with Mysql Select

Note:
1. Do not forget to add the mysql java connection jar.
2. Mention the username, password and database name correctly.
3. Mention the column names, column name types and table names correctly.

Java Recommended Books:

How to increase the JVM heap size in web sphere?

How to increase the JVM heap size in web sphere?

1. By Server Console

Servers -> Server Types -> WebSphere application servers -> Java and Process Management -> Process definition -> Java Virtual Machine -> Configuration

Enter the values in,

 Initial heap size and Maximum heap size text boxes.

(256m and 1024m) are recommended.

2. By Server.xml file:

C:\Program Files\IBM\SDP\runtimes\base_v7\profiles\AppSrv01\config\cells\Node03Cell\nodes\Node03\servers\server1

Open the server.xml file and search with heap,

<jvmEntries initialHeapSize="256m" maximumHeapSize="1024m">

Change the above values accordingly.

[Solved] Warning: session_start() [function.session-start]: Cannot send session cache limiter – headers already sent (output started at

Warning: session_start() [function.session-start]: Cannot send session cache limiter – headers already sent (output started at
session_start() should be used first line in the php code and php code should exist even above the html tag.

session1.php:

<html>
<?php
session_start();
$check = 0;
if(isset($_SESSION['var1'])){
$check =1;
}
?>
<head>
</head>
<body>
<?php
if($check==1){
?>
With Session
<?php
}else{
?>
Without Session.
<a href="session2.php">Click here to initate the session</a>
<?php
}
?>
</body>
</html>

session2.php:

<?php
session_start();
$_SESSION['var1']='Javadomain.in';
header ("Location: session1.php");
?>

Output:
without session issue

As discussed already, if you move the php part to before the html tag, then we will not be getting the issue.

session1.php:

<?php
session_start();
$check = 0;
if(isset($_SESSION['var1'])){
$check =1;
}
?>
<html>
<head>
</head>
<body>
<?php
if($check==1){
?>
With Session
<?php
}else{
?>
Without Session.
<a href="session2.php">Click here to initate the session</a>
<?php
}
?>
</body>
</html>

session2.php:

<?php
session_start();
$_SESSION['var1']='Javadomain.in';
header ("Location: session1.php");
?>

Now output is,
without session

PHP Recommended Books:

Header, Body and Footer Html CSS Example

Header, Body and Footer Html CSS Example:

Html Code:

<!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>Learn</title>
</head>
<body>
<div id="container">
<div class="header">Header</div>
    <div class="mainbody">
    Body
    </div>
    <div class="footer">Footer</div>
</div>
</body>
</html>

CSS Code:

<style type="text/css">
.container {
    width: 500px;
    max-height: 500px;
    margin: 10px;
    border: 1px solid #fff;
    background-color: #ffffff;
    box-shadow: 0px 2px 7px #292929;
    -moz-box-shadow: 0px 2px 7px #292929;
    -webkit-box-shadow: 0px 2px 7px #292929;
    border-radius: 10px;
    -moz-border-radius: 10px;
    -webkit-border-radius: 10px;
}
.mainbody,
.header,
.footer {
    padding: 5px;
}
.mainbody {
    margin-top: 0;
    min-height: 150px;
    max-height: 540px;
    overflow: auto;
	height:499px;
	text-align:center;
}
.header {
    height: 40px;
    border-bottom: 1px solid #EEE;
    background-color: #ffffff;
    height: 40px;
    -webkit-border-top-left-radius: 5px;
    -webkit-border-top-right-radius: 5px;
    -moz-border-radius-topleft: 5px;
    -moz-border-radius-topright: 5px;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
		width:100%;
}
.footer {
    height: 40px;
    background-color: whiteSmoke;
    border-top: 1px solid #DDD;
    -webkit-border-bottom-left-radius: 5px;
    -webkit-border-bottom-right-radius: 5px;
    -moz-border-radius-bottomleft: 5px;
    -moz-border-radius-bottomright: 5px;
    border-bottom-left-radius: 5px;
    border-bottom-right-radius: 5px;
	width:100%;
}
 

</style>

Output:

header, body and footer

Recommended Html/Css/jQuery Books: