Hi,
What I'm trying to do is validate a date entered by users in a text field(in a form) for the YYYY-MM-DD formate (including the "-"). I have two problems-
1.) I dont know where to run the function, is it onSumbit for the form tag, or do I echo it?
2.) how do I get the function to recognize my text field
<form method="post" action="" name="addeditform" id="addeditform" >
<td valign="top">Posted: </td>
<td ><input type="text" name="posted" id="posted" value="<? echo htmlspecialchars(stripslashes($posted), ENT_QUOTES); ?>"</td>
</tr><tr>
<td width="25%"><input type="submit" name="exe_save" class="submit" value="Save and close" style="width:100%"/></td>
</form>
<?
if(isset($_POST['exe_save'])) {
$posted = trim($_POST['posted']);
$error = "";
function checkData($posted)
{
if (!isset($posted) || $posted=="")
{
$error .= "<li>Posting date is required and needs to be valid.</li>";
}
list($yy,$mm,$dd)=explode("-",$posted);
if ($yy!="" && $mm!="" && $dd!="" || strlen(($yy) != 4) && strlen(($mm) > 2) && strlen(($yy) > 2 ))
{
if (is_numeric($yy) && is_numeric($mm) && is_numeric($dd))
{
return checkdate($yy,$mm,$dd);
}
}
$error .= "<li>Posting date is required and needs to be valid.</li>";
}
?>
So basically, how do I run the function once Submit is hit. Thanks in advance for any input given.