Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5d15cf9

Browse files
Fxed issue of doble textbox selection
1 parent 0e23dd6 commit 5d15cf9

File tree

7 files changed

+969
-0
lines changed

7 files changed

+969
-0
lines changed

‎connection.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php mysql_connect("localhost", "root", "");
2+
mysql_select_db("validation");
3+
?>

‎index.php‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<title>Postnidea | Jquery Form validation with database using php</title>
2+
<head>
3+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
4+
<style type="text/css">
5+
body{
6+
margin-top: 20px;
7+
}
8+
h3.heading {
9+
border-bottom: 3px solid #cccc;
10+
font-size: 17px;
11+
margin-bottom: 17px;
12+
margin-left: 16px;
13+
padding: 0 0 11px;
14+
width: 94%;
15+
}
16+
input[type=submit]{
17+
margin-left: 16px;
18+
}
19+
input[type=submit]+.alert-success{
20+
float: right;
21+
margin-right: 15px;
22+
padding: 6px;
23+
width: 77%;
24+
}
25+
.myform{
26+
height: 295px;
27+
}
28+
29+
</style>
30+
</head>
31+
<body>
32+
<div class="container">
33+
<div class="row">
34+
<div class="col-md-6 myform">
35+
<h3 class="heading">Form with error & success message</h3>
36+
<form id="case1" action="process.php?case=case1">
37+
<div class="col-md-6 form-group"><input type="text" class="form-control" name="fname" placeholder="Full Name"></div>
38+
<div class="col-md-6 form-group"><input type="text" class="form-control" name="username" placeholder="username"></div>
39+
<div class="col-md-6 form-group"><input type="password" class="form-control" name="password" placeholder="Password"></div>
40+
<div class="col-md-6 form-group"><input type="password" class="form-control" name="password1" placeholder="Confirm Password"></div>
41+
42+
<input type="submit" class="btn btn-primary" id="case1_button" value="Case 1">
43+
</form>
44+
</div>
45+
46+
<div class="col-md-6 myform">
47+
<h3 class="heading">Form with callback function</h3>
48+
<form id="case2" action="process.php?case=case2">
49+
<div class="col-md-6 form-group"><input type="text" class="form-control" name="fname1" placeholder="Full Name"></div>
50+
<div class="col-md-6 form-group"><input type="text" class="form-control" name="username1" placeholder="username"></div>
51+
<div class="col-md-6 form-group"><input type="password" class="form-control" name="password2" placeholder="Password"></div>
52+
<div class="col-md-6 form-group"><input type="password" class="form-control" name="password3" placeholder="Confirm Password"></div>
53+
54+
<input type="submit" class="btn btn-primary" id="case2_button" value="Case 2">
55+
</form>
56+
</div>
57+
58+
59+
<div class="col-md-6 myform">
60+
<h3 class="heading">Form success redirect to another page</h3>
61+
<form id="case3" action="process.php?case=case3">
62+
<div class="col-md-6 form-group"><input type="text" class="form-control" name="fname3" placeholder="Full Name"></div>
63+
<div class="col-md-6 form-group"><input type="text" class="form-control" name="username3" placeholder="username"></div>
64+
<div class="col-md-6 form-group"><input type="password" class="form-control" name="password4" placeholder="Password"></div>
65+
<div class="col-md-6 form-group"><input type="password" class="form-control" name="password5" placeholder="Confirm Password"></div>
66+
67+
<input type="submit" class="btn btn-primary" id="case3_button" value="Case 3">
68+
</form>
69+
</div>
70+
</div>
71+
</div>
72+
</body>
73+
<script type="text/javascript" src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
74+
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
75+
<script type="text/javascript" src="js/jquery.server_validation.js"></script>
76+
<script type="text/javascript" src="js/myscript.js"></script>

‎js/jquery.server_validation.js‎

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
Validation Plugin
3+
Created on : Thursday, June 13, 2013
4+
Programmer : Shishir raven
5+
6+
Description: adds valiation to the form specified checking the form Server Side.
7+
8+
How to use:
9+
10+
Step 1 : Include this file into the form file
11+
12+
Step 2: Write the following code
13+
14+
$('#button_id').server_validation({
15+
form_id:'myform_without#',
16+
validtion_script:'services/script_that_will_return_json.php'
17+
});*/
18+
19+
jQuery.fn.server_validation = function(options){
20+
//For each matching class
21+
var settings = jQuery.extend({
22+
form_id :"myfrom",
23+
button_id : "",
24+
validtion_script:"services/somescript.php",
25+
before_validate_callback:function(){
26+
},
27+
after_success:function(){
28+
}
29+
},options);
30+
31+
//this.each(function(){
32+
33+
var element =$(this);
34+
35+
var element_id=$(element).attr('id');
36+
37+
//$(element).click(function(){
38+
$(document).on("click", '#'+settings.button_id, function() {
39+
40+
if(typeof(settings.before_validate_callback) == "function")
41+
{
42+
settings.before_validate_callback();
43+
}
44+
var button_name = $(element).html();
45+
//$(element).button('loading');
46+
47+
var formdata= $('#'+settings.form_id).serialize();
48+
var filetype = "";
49+
$('input[type=file]',$('#'+settings.form_id)).each(function(){
50+
param_name = $(this).attr('name');
51+
param_value = $(this).val();
52+
filetype = filetype + '&'+param_name+"="+param_value;
53+
})
54+
55+
formdata = formdata + filetype;
56+
57+
$.ajax({
58+
type: "POST",
59+
url: $('#'+settings.form_id).attr("action"),
60+
data: formdata,
61+
dataType:"json",
62+
beforeSend:function(){ $(element).html("loading"); },
63+
success: function(error_obj)
64+
{
65+
$('.error-message').remove();
66+
$('.control-group').removeClass('has-error');
67+
$('.form-group').removeClass('has-error');
68+
if(error_obj.status==false)
69+
{
70+
71+
$('#'+settings.button_id).after(alert_message(error_obj.data[0].error));
72+
//for redirecting the page after successful complete
73+
if(error_obj.data.length>1 && error_obj.data[1].link.length>0){
74+
location.href= error_obj.data[1].link;
75+
}
76+
77+
//$('#'+settings.form_id)[0].reset();
78+
$(element).html(button_name);
79+
$(element).removeAttr('disabled');
80+
$(element).removeClass('disabled');
81+
82+
//call the callback fundtion
83+
if(typeof(settings.after_success) == "function"){
84+
settings.after_success.call();
85+
}
86+
} else {
87+
88+
var top = 50000;
89+
var error = error_obj.data
90+
for(var x in error)
91+
{
92+
$("<span class='help-block error-message'> "+error[x].error+"</span>").insertAfter('[name="'+error[x].error_field+'"]');
93+
$('[name="'+error[x].error_field+'"]').parent().addClass('has-error');
94+
elemt_top = parseInt($("[name="+error[x].error_field+"]").offset().top);
95+
if(elemt_top<top)
96+
{
97+
top = elemt_top;
98+
}
99+
}
100+
101+
$('html,body').animate({scrollTop: top-100},'slow');
102+
$(element).html(button_name);
103+
$(element).removeAttr('disabled');
104+
$(element).removeClass('disabled');
105+
106+
}
107+
108+
}
109+
})
110+
return false;
111+
});
112+
//});
113+
}
114+
115+
116+
//reset error inputs
117+
$(document).on('click',"input[type='reset'],button[type='reset']",function(){
118+
$(".form-group").removeClass("has-error");
119+
$("span.help-block").remove();
120+
121+
});
122+
123+
function goToByScroll(element_name){
124+
$('html,body').animate({
125+
scrollTop: parseInt($("[name="+element_name+"]").offset().top)-100},
126+
'slow');
127+
}
128+
129+
function alert_message(message){
130+
var message = '<div class="alert alert-success fade in"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>'+message+'</div>';
131+
return message;
132+
}

‎js/myscript.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
$('#case1_button').server_validation({form_id:'case1',button_id:'case1_button'});
2+
$('#case2_button').server_validation({form_id:'case2',button_id:'case2_button',after_success:callback_function});
3+
$('#case3_button').server_validation({form_id:'case3',button_id:'case3_button'});
4+
5+
function callback_function(){
6+
alert("You can load other things or manupulate the other DOM elements");
7+
}

‎process.php‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
include("validation.php");
3+
4+
if(isset($_GET['case']) && $_GET['case']=="case1"){
5+
$config = array();
6+
$config['array_to_validate'] = $_POST;
7+
$config['required'] = "fname,username,password,password1";
8+
$config['unique_from_table'] = array(array('field_name' =>'username','table_name' =>'user','table_field'=>'username'));
9+
$config['compare']= array(array('field_name' =>'password','compare_field_name' =>'password1'));
10+
11+
$validate = new validator($config);
12+
$error = $validate->process_validation();
13+
14+
if($error==false){
15+
$mesasge = array(array("error_field"=>"","error"=>"Your data saved successfully"));
16+
$modified_array= array("status"=>false,"data"=>$mesasge);
17+
18+
} else {
19+
$username = mysql_real_escape_string($_POST['username']);
20+
$fullname = mysql_real_escape_string($_POST['fname']);
21+
$password = mysql_real_escape_string($_POST['password']);
22+
23+
mysql_query("INSERT INTO `user` (`username`, `password`, `fullname`) VALUES ('".$username."', '".md5($password)."', '".$fullname."');");
24+
$modified_array= array("status"=>true,"data"=>$error);
25+
26+
}
27+
echo json_encode($modified_array);
28+
die;
29+
}
30+
if(isset($_GET['case']) && $_GET['case']=="case2"){
31+
$config = array();
32+
$config['array_to_validate'] = $_POST;
33+
$config['required'] = "fname1,username1,password2,password3";
34+
$config['unique_from_table'] = array(array('field_name' =>'username1','table_name' =>'user','table_field'=>'username'));
35+
$config['compare']= array(array('field_name' =>'password2','compare_field_name' =>'password3'));
36+
37+
$validate = new validator($config);
38+
$error = $validate->process_validation();
39+
40+
if($error==false){
41+
$mesasge = array(array("error_field"=>"","error"=>"Your data saved successfully"));
42+
$modified_array= array("status"=>false,"data"=>$mesasge);
43+
44+
} else {
45+
$username = mysql_real_escape_string($_POST['username1']);
46+
$fullname = mysql_real_escape_string($_POST['fname1']);
47+
$password = mysql_real_escape_string($_POST['password2']);
48+
49+
mysql_query("INSERT INTO `user` (`username`, `password`, `fullname`) VALUES ('".$username."', '".md5($password)."', '".$fullname."');");
50+
$modified_array= array("status"=>true,"data"=>$error);
51+
52+
}
53+
echo json_encode($modified_array);
54+
die;
55+
}
56+
57+
if(isset($_GET['case']) && $_GET['case']=="case3"){
58+
59+
$config = array();
60+
$config['array_to_validate'] = $_POST;
61+
$config['required'] = "fname3,username3,password4,password5";
62+
$config['unique_from_table'] = array(array('field_name' =>'username3','table_name' =>'user','table_field'=>'username'));
63+
$config['compare']= array(array('field_name' =>'password4','compare_field_name' =>'password5'));
64+
65+
$validate = new validator($config);
66+
$error = $validate->process_validation();
67+
68+
if($error==false){
69+
$mesasge = array(array("error_field"=>"","error"=>"Your data saved successfully"),array("error_field"=>"","link"=>"http://google.com"));
70+
$modified_array= array("status"=>false,"data"=>$mesasge);
71+
72+
} else {
73+
$username = mysql_real_escape_string($_POST['username3']);
74+
$fullname = mysql_real_escape_string($_POST['fname3']);
75+
$password = mysql_real_escape_string($_POST['password4']);
76+
77+
mysql_query("INSERT INTO `user` (`username`, `password`, `fullname`) VALUES ('".$username."', '".md5($password)."', '".$fullname."');");
78+
$modified_array= array("status"=>true,"data"=>$error);
79+
80+
}
81+
echo json_encode($modified_array);
82+
die;
83+
84+
85+
}
86+
87+
?>

‎user.sql‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
-- phpMyAdmin SQL Dump
2+
-- version 4.5.0.2
3+
-- http://www.phpmyadmin.net
4+
--
5+
-- Host: 127.0.0.1
6+
-- Generation Time: Jan 14, 2017 at 05:56 PM
7+
-- Server version: 10.0.17-MariaDB
8+
-- PHP Version: 5.5.30
9+
10+
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
11+
SET time_zone = "+00:00";
12+
13+
14+
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
15+
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
16+
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
17+
/*!40101 SET NAMES utf8mb4 */;
18+
19+
--
20+
-- Database: `validation`
21+
--
22+
23+
-- --------------------------------------------------------
24+
25+
--
26+
-- Table structure for table `user`
27+
--
28+
29+
CREATE TABLE `user` (
30+
`id` int(11) NOT NULL,
31+
`username` varchar(50) NOT NULL,
32+
`password` varchar(50) NOT NULL,
33+
`fullname` varchar(50) NOT NULL
34+
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
35+
36+
--
37+
-- Dumping data for table `user`
38+
--
39+
40+
INSERT INTO `user` (`id`, `username`, `password`, `fullname`) VALUES
41+
(1, '', 'd41d8cd98f00b204e9800998ecf8427e', ''),
42+
(2, '', 'd41d8cd98f00b204e9800998ecf8427e', ''),
43+
(3, '', 'd41d8cd98f00b204e9800998ecf8427e', ''),
44+
(4, '', 'd41d8cd98f00b204e9800998ecf8427e', ''),
45+
(5, '', 'd41d8cd98f00b204e9800998ecf8427e', ''),
46+
(6, '', 'd41d8cd98f00b204e9800998ecf8427e', ''),
47+
(7, '', 'd41d8cd98f00b204e9800998ecf8427e', ''),
48+
(8, '', 'd41d8cd98f00b204e9800998ecf8427e', ''),
49+
(9, '', 'd41d8cd98f00b204e9800998ecf8427e', ''),
50+
(10, '', 'd41d8cd98f00b204e9800998ecf8427e', ''),
51+
(11, '', 'd41d8cd98f00b204e9800998ecf8427e', ''),
52+
(12, '', 'd41d8cd98f00b204e9800998ecf8427e', ''),
53+
(13, '', 'd41d8cd98f00b204e9800998ecf8427e', ''),
54+
(14, '', 'd41d8cd98f00b204e9800998ecf8427e', ''),
55+
(15, '', 'd41d8cd98f00b204e9800998ecf8427e', ''),
56+
(16, '', 'd41d8cd98f00b204e9800998ecf8427e', ''),
57+
(17, '', 'd41d8cd98f00b204e9800998ecf8427e', ''),
58+
(18, '', 'd41d8cd98f00b204e9800998ecf8427e', ''),
59+
(19, '', 'd41d8cd98f00b204e9800998ecf8427e', '');
60+
61+
--
62+
-- Indexes for dumped tables
63+
--
64+
65+
--
66+
-- Indexes for table `user`
67+
--
68+
ALTER TABLE `user`
69+
ADD PRIMARY KEY (`id`);
70+
71+
--
72+
-- AUTO_INCREMENT for dumped tables
73+
--
74+
75+
--
76+
-- AUTO_INCREMENT for table `user`
77+
--
78+
ALTER TABLE `user`
79+
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=20;
80+
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
81+
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
82+
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /