Validate data using alert()

Discussing Html . Code , Software , other

Moderators: egami, macek, gesf

Post Reply
User avatar
popeye
New php-forum User
New php-forum User
Posts: 121
Joined: Sat Jan 03, 2004 7:06 pm
Location: New York, NY

Sat Sep 15, 2007 1:26 pm

I am trying to validate the user's input. See codes below:

Code: Select all

<?php
$i_name='Your Name';
$i_s="
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'> 
<html xmlns='http://www.w3.org/1999/xhtml'> 
<head> 
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' /> 
<title>Untitled Document</title> 
</head> 
<body> 
<script type='text/javascript'> 
function checkForm(frm){ 
msg = ''; 
   if(!frm.Name.value){ 
      msg +=' - Name is a required field\n'; 
   } 
   if(!frm.Email.value){ 
      msg +=' - Email is a required field\n'; 
   } 
   if(!frm.Comments.value){ 
      msg += ' - Comments is a required field\n'; 
   } 
    
   if(msg){ 
      alert('There was an error with your form:\n' + msg); 
      return false;
	 }
	
	 document.form1.action='GoDoIt.php'; document.form1.submit();
}
</script> 
<form id='form1' name='form1' method='post' action='' onsubmit='return checkForm(this)'> 
    Name:<input name='Name' type='text' id='Name'  value='".$i_name."'> 
    Email:<input name='Email' type='text' id='Email'> 
    Comments:<textarea name='Comments' id='Comments'></textarea> 
    Submit:<input type='submit' name='Submit' value='Submit'> 
</form> 
</body> 
</html>";
echo $i_s;
?>

But when the submit is clicked, I do not get the Alerts and/or GoDoIt.php is never called because of "error on page". Any ideas? Thanks.
The greatest enemy of knowledge is
not ignorance; it is the illusion of knowledge.
-Stephen Hawking

User avatar
popeye
New php-forum User
New php-forum User
Posts: 121
Joined: Sat Jan 03, 2004 7:06 pm
Location: New York, NY

Tue Sep 18, 2007 5:55 am

There must be something wrong with all you guys. I have not received any reply to my last posts. AT least let me know if there is anything wrong with my post or something else that I do not know :?
The greatest enemy of knowledge is
not ignorance; it is the illusion of knowledge.
-Stephen Hawking

User avatar
popeye
New php-forum User
New php-forum User
Posts: 121
Joined: Sat Jan 03, 2004 7:06 pm
Location: New York, NY

Thu Sep 20, 2007 12:32 pm

:)

Thanks a lot. I see my mistake. I appreciate your respond.

:D
The greatest enemy of knowledge is
not ignorance; it is the illusion of knowledge.
-Stephen Hawking

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 0 guests