Hello Friends,
I am working on PHP and I am totally new to PHP. I want to validate the text boxes of this form. As it contains two text boxes with two buttons as cancel and save. I want when user click on save button it checks either the text boxes are empty or not. and if empty then display * very next to text boxes and not empty made a call to save function....
My code is as
<?php
session_start();
if(!$_SESSION['sessionusername'])
{
header("location:index.php");
}
else
{
include ('connection2.php');
$local_session = $_SESSION['sessionusername'] ;
$depnameErr = $depidErr= "";
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$depname = $depid = "";
if (empty($_POST['text_depname']))
{
$depnameErr = "*";
}
else
{
$depname = $_POST['text_depname'];
}
if(empty($_POST['text_deptid']))
{
$depidErr = "*";
}
else
{
$depid = $_POST['text_deptid'];
}
if(($depname != "") && ($depid != ""))
{
if(isset($_POST["btn_save"]))
{
$error_val = save_fxn($depid,$depname);
}
}
}
}
?>
<!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" />
<link rel="stylesheet" media="screen" href="css/master.css">
<link rel="stylesheet" media="screen" href="css/menus.css">
<title>Phytec India</title>
</head>
<body>
<form method="POST" action=<?php
if(isset($_POST['s_close']))
{
header("location:department.php");
}
elseif(isset($_POST["btn_save"]))
{
"newdepartment.php";
}
?>
<div id="welcome">
<div id="welcome_text">Welcome <?php echo "$local_session" ?> <a href="logout.php">Signout</a></div>
</div>
And some part of the code form text point of view
<td id="table_controls" >
<div id="text_controls">
<input type="text" maxlength="6" name="text_depid" width="auto" style="height:15px;"/>
<span class="error"><?php echo $depidErr;?></span>
</div>
</td>
<td id="table_controls">
<div id="text_controls">
<input type="text" maxlength="30" name="text_depname" width="auto" style="height:15px;"/>
<span class="error"><?php echo $depnameErr;?></span>
</div>
</td>
And button code is as
<td>
<div id="nav_btn">
<input type="submit" name="btn_save" value="Save" onSubmit="save_fxn();" />
<input type="submit" name="s_close" value="Close" />
</div>
</td>
Please help me to solve the problem