marf
02-15-2006, 07:57 PM
OK basically I have a form, and when I submit, i want php to check to see if it has all the values, and if something is incorrect, i want it to change the style of the table around the input field so the user knows that they must correct it.
Here is a simple version of the basic concept
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<?php
if($_POST['action'] == 'submitted' && $_POST['name'] == ''){//name is blank
echo "<script type=\"text/javascript\">document.getElementById('tname').style.border = '2px solid #FF0000'</script>";
?>
<form action="form.php" method="post" name="testing">
<table width="320" border="0" cellpadding="4" cellspacing="0" align="center">
<tr>
<td>Name: </td>
<td id="tname"><input name="name" type="text" size="18" maxlength="50" /></td>
</tr>
<tr>
<td colspan="2"><input type="hidden" name="action" value="submitted" /><input type="submit" value="Submit" /></td>
</table>
</form>
</body>
</html>
This is a dummied down version. Basically if they forget to fill in their name, it checks and then outlines the box. I guess some people might reply back and say "Why arne't you checking to see if(document.test.name.value == '') basically get rid of PHP all together. Well im doing it this way. If you have a more efficient way using javascript im up for suggestions. Also is their an easy way to 'share' or pass data between javascript easily? The only way i can think of at this moment is to have a <input type="hidden" value="information> then have javascript read that, or vice versa. I can't think of another way.
Thanks for your responses in advance.
Mike
Here is a simple version of the basic concept
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<?php
if($_POST['action'] == 'submitted' && $_POST['name'] == ''){//name is blank
echo "<script type=\"text/javascript\">document.getElementById('tname').style.border = '2px solid #FF0000'</script>";
?>
<form action="form.php" method="post" name="testing">
<table width="320" border="0" cellpadding="4" cellspacing="0" align="center">
<tr>
<td>Name: </td>
<td id="tname"><input name="name" type="text" size="18" maxlength="50" /></td>
</tr>
<tr>
<td colspan="2"><input type="hidden" name="action" value="submitted" /><input type="submit" value="Submit" /></td>
</table>
</form>
</body>
</html>
This is a dummied down version. Basically if they forget to fill in their name, it checks and then outlines the box. I guess some people might reply back and say "Why arne't you checking to see if(document.test.name.value == '') basically get rid of PHP all together. Well im doing it this way. If you have a more efficient way using javascript im up for suggestions. Also is their an easy way to 'share' or pass data between javascript easily? The only way i can think of at this moment is to have a <input type="hidden" value="information> then have javascript read that, or vice versa. I can't think of another way.
Thanks for your responses in advance.
Mike