I'm a newbie in php. I want to validate a form and set the form data to the session variables so as to use them onto next page. here is the code,
<?php
session_start();
?>
<html>
<head>
<script type="text/javascript">
function val(){
var n=document.f.cname.value;
if(n==""||n==null){
alert("Please enter name field.");
return false;
}
}
</script>
</head>
<body>
<form method="post" action="<?php $_Php_SELF?>" onsubmit="return val()">
name : <input type="text" name="cname" />
<input type="Submit" name="submit" value="Sub"/>
</form>
<?php
if(isset($_POST['submit'])){
$_SESSION['caname']=$_POST['cname'];
header("location:sessiontest2.php");
}
?>
</body>
</html>
The second page just echos the session variable. Without validation it works fine.