piropeator
May 5th 2008, 3:54 pm
I want to validate my form but does not work.
These are my files: form_input.html and form_view.php only to display.
What is the problem?
******* form_input.html
<html>
<title>Input</title>
<script>
function valida_envia(){
//validate name
if (document.fvalida.name.value.length==0){
alert("Write a name")
document.fvalida.name.focus()
return 0;
} else {
// It's OK
alert("The name is OK!");
document.fvalida.submit();
}
}
</script>
</head>
<body>
<form name="fvalida" onsubmit="return valida_envia();" method="POST" action="form_view.php">
<table width="383" border="0" bgcolor="#FFFFFF">
<tr>
<th scope="row"><div align="right">Nombre :</div></th>
<td><input type="text" name="name"/></td>
</tr>
<tr>
<th colspan="2" scope="row">
<input type="submit" value="Input"/> </th>
</tr>
</table>
</form>
</body>
</html>
***** form_view.php
<head>
<title>EJEMPLO</title>
</head>
<body>
The name is : <?php echo $_POST['name'] ?>
</body>
</html>
These are my files: form_input.html and form_view.php only to display.
What is the problem?
******* form_input.html
<html>
<title>Input</title>
<script>
function valida_envia(){
//validate name
if (document.fvalida.name.value.length==0){
alert("Write a name")
document.fvalida.name.focus()
return 0;
} else {
// It's OK
alert("The name is OK!");
document.fvalida.submit();
}
}
</script>
</head>
<body>
<form name="fvalida" onsubmit="return valida_envia();" method="POST" action="form_view.php">
<table width="383" border="0" bgcolor="#FFFFFF">
<tr>
<th scope="row"><div align="right">Nombre :</div></th>
<td><input type="text" name="name"/></td>
</tr>
<tr>
<th colspan="2" scope="row">
<input type="submit" value="Input"/> </th>
</tr>
</table>
</form>
</body>
</html>
***** form_view.php
<head>
<title>EJEMPLO</title>
</head>
<body>
The name is : <?php echo $_POST['name'] ?>
</body>
</html>