You are on page 1of 8

Name: Pradip Ratilal Jadhav

Enrollment No: 2114320056

College: Government Polytechnic Nandurbar

Class: CO5I

Course: Computer Engineering

Assignment No. 21
Code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Form Validation With Javascript</title>

<!-- Latest compiled and minified CSS -->


<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/
K68vbdEjh4u" crossorigin="anonymous">

<!-- Optional theme -->


<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css"
integrity="sha384-
rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp"
crossorigin="anonymous">

<!-- Latest compiled and minified JavaScript -->


<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
integrity="sha384-
Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
crossorigin="anonymous"></script>
</head>
<body>
<div class="jumbotron" style="background-color: purple;color: ghostwhite;margin-top: -
20px;"><h2 align="center"><strong>Form Validation With Javascript</strong></h2></div>
<div class="container">
<script type="text/javascript">
function Form_Validation(argument) {
var a=document.forms["Form1"]["name"].value;
if(a==""){
alert("Please Enter Name...");
document.Form1.name.focus();
return false;
}
var b=document.forms["Form1"]["email"].value;
if(b==""){
alert("Please Enter Email...");
document.Form1.email.focus();
return false;
}

var c=document.forms["Form1"]["mobile"].value;
if(c==""){
alert("Please Enter Mobile Number...");
document.Form1.mobile.focus();
return false;
}

var d=document.forms["Form1"]["address"].value;
if(d==""){
alert("Please Enter Address...");
document.Form1.address.focus();
return false;
}

var e=document.forms["Form1"]["gen"].value;
if(e==""){
alert("Please Select Gender...");
return false;
}

var check=document.getElementsByName("n[]");
if ((check[0].checked==false) && (check[1].checked==false) &&
(check[2].checked==false) && (check[3].checked==false))
{
alert("Please Select Qualification...");
return false;
}
}
</script>

<?php
$connect=mysqli_connect("localhost","root","","db_1") or die($connect);
if ($connect){
echo "<center><h4>Database Connected<h4></center>";
}else{
echo "<center><h4>Connection Error<h4></center>";

if (isset($_POST['Submit'])){
extract($_POST);

$s=implode(',', $n);

$insert =mysqli_query($connect,"insert into


form(name,email,mobile_no,address,gender,qualification)values('$name','$email','$mobile',
'$address','$gen','$s')") or die(mysqli_error($connect));

if ($insert){
echo "<script>";
echo "alert('Registration Successful');";
echo "window.location.href='p2.php';";
echo "</script>";
}
else{
echo "<script>";
echo "alert('Error');";
echo "window.location.href='form.php';";
echo "</script>";
}
}
?>

<div class="row">
<div class="col-md-4"></div>
<div class="col-md-4">
<form style="border-style: solid;padding:10px;background-
color:ghostwhite;" name="Form1" method="post" onsubmit="return Form_Validation()">
<label>Name</label>
<input type="text"
oninput="this.value=this.value.replace(/[^a-zA-Z\s]/g,'').replace(/(..*)\./g,'$1'); "name="name"
class="form-control" placeholder="Name"><br>
<label>Email</label>
<input type="email" name="email" class="form-control"
placeholder="Email"><br>
<label>Mobile No.</label>
<input type="tel" pattern="[789]{1}[0-9]{9}"
maxlength="10" name="mobile" class="form-control" placeholder="Mobile No.">
<br>
<label>Address</label>
<textarea class="form-control"
name="address"></textarea><br>
<label>Gender</label>&nbsp;
<input type="radio" name="gen" value="Female">Female
<input type="radio" name="gen" value="Male">Male<br>
<br><label>Qualification</label><br>
<input type="checkbox" name="n[]" value="SSC">SSC
&nbsp;
<input type="checkbox" name="n[]" value="HSC">HSC
&nbsp;
<input type="checkbox" name="n[]"
value="Diploma">Diploma &nbsp;
<input type="checkbox" name="n[]" value="B.E.">B.E.
&nbsp;
<input type="checkbox" name="n[]"
value="B.Tech">B.Tech &nbsp;

<center><br><input type="submit" name="Submit"


class="btn btn-success"></center>
</form><br>
</div>
<div class="col-md-4"></div>
</div>
</div>

</body>
</html>

Output:
Form Filling:
After submitting form:

Redirect to this page:


Before submitting form:

After submitting form:

You might also like