I tried using
function confirm($msg)
{
echo "<script langauge=\"javascript\">alert(\"".$msg."\");</script>";
}//end function
// to validate
function save()
{
$first_name = '';
$last_name = '';
$email = '';
$id = '';
$first_name = $_POST['last_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$id = $_POST['id'];
//Then I used this alert to validate missing fields However it not respnnding to da php script it work only with JS script below.... any assistance please
if (($first_name=='')||($last_name=='')||($email==''))
{
$msg = "Some data from the form was forgotten. Please fill in the entire form.";
confirm($msg);
}//end if
}
Code: Select all
<?php
<script type="text/javascript">
function save()
{
if (document.form1.first_name.value=="")
{
alert("Opponent's Name must be filled.");
form1.first_name.focus();
return false;
}
if (document.form1.last_name.value=="")
{
alert("last_name must be filled.");
form1.last_name.focus();
return false;
}
if (document.form1.email.value=="")
{
alert("email must be filled.");
form1.email.focus();
return false;
}
var confirm_del= confirm ("Do you want to save this fixture ?")
if (confirm_del)
{
document.form1.action.value="Save";
document.form1.action="test.php";
document.form1.method="post";
document.form1.submit();
}
}
function editrecord(i)
{
if(Number(form1.rcount.value)>1)
{
form1.id.value=form1.hid_id[i].value;
form1.first_name.value=form1.hid_first_name[i].value;
form1.last_name.value=form1.hid_last_name[i].value;
form1.email.value=form1.hid_email[i].value;
}
else
{
form1.id.value=form1.hid_id.value;
form1.first_name.value=form1.hid_first_name.value;
form1.last_name.value=form1.hid_last_name.value;
form1.email.value=form1.hid_email.value;
}
}
function del_record()
{
if (document.form1.id.value=="0")
{
alert("Nothing to delete.");
form1.txtOppenents.focus();
return false;
}
var confirm_del= confirm ("Do you want to really delete this user ?")
if (confirm_del)
{
document.form1.f_action.value="delete";
document.form1.action="test.php";
document.form1.method="post";
document.form1.submit();
}
}
</script>
<body>
<form Name="form1" action="test.php" Method="post">
<TABLE border="0" width="750" align="center">
<tr>
<td align="center">
<font face="verdana" size="2" color="#000000"><STRONG>User Details</STRONG>
</font></td>
</tr>
</table>
<table border="0" width="600" align="center" CELLPADDING="0" CELLSPACING="0">
<tr> <td>
<table border="0" width="600" align="center" CELLPADDING="0" CELLSPACING="0">
<input type="hidden" value="1" name="submit">
<input type="hidden" name="action">
<input type="hidden" name="id" value="0">
<tr bgcolor="#fff5ee">
<td height="10" colspan="6"></td>
</tr>
<tr bgcolor="#fff5ee">
<td align="right" width="40%">
<font face="verdana" size="2" color="#000000">First Name
</font></td>
<td align="center" width="5%">
<font face="verdana" size="2" color="#000000">:
</font></td>
<td align="left" width="55%">
<input type="text" size="40" class=in name="first_name"></td>
</tr>
<tr bgcolor="#fff5ee">
<td align="right" width="40%" valign="top">
<font face="verdana" size="2" color="#000000">LastName
</font></td>
<td align="center" width="5%" valign="top">
<font face="verdana" size="2" color="#000000">:
</font></td>
<td align="left" width="55%">
<input type="text" size="40" class=in name="last_name"></td>
</tr>
<tr bgcolor="#fff5ee">
<td align="right" width="40%">
<font face="verdana" size="2" color="#000000">Email
</font></td>
<td align="center" width="5%">
<font face="verdana" size="2" color="#000000">:
</font></td>
<td align="left" width="55%">
<input type="text" size="40" class=in name="email"></td>
</tr>
<tr bgcolor="#fff5ee">
<td height="10" colspan="6"></td>
</tr>
<tr bgcolor="#fff5ee">
<td colspan="4" align="center">
<input type="button" value="Add" onClick="save()">
<input type="button" value="DEL" onClick="del_record()">
</td>
</tr>
<tr bgcolor="#fff5ee">
<td height="10" colspan="6"></td>
</tr>
</table> </td>
</tr>
</table>
<TABLE border="0" width="750" align="center">
<tr>
<td align="center">
</font></td>
</tr>
</table>