PHP] simple form validation
| From: | Jacky | Date: | Wed, 06 Dec 2000 17:35:13 +0000 |
| Subject: | PHP] simple form validation | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-28842@lists.php.net to get a copy of this message | ||
Dear Mark,
I did put in the javascript validation as below and the problem is that it
does not really execute. I made it to execute at the "onsubmit" as usual. I
am not sure if it has anything to do with the fact that I did put the html
part in the "print" command like below:
var charexp = /./
function hasChar(str) {
return charexp.test(str);
}
function checkform(form) {
if (!hasChar(form.No_of_Persons.value)) {
alert("You must enter your first name");
form.firstname.focus();
return false;
}
if (!hasChar(form.No_of_Overnights.value)) {
alert("You must enter your last name");
form.lastname.focus();
return false;
}
alert("Data valid");
return true;
}
<?
print("<form action='https://www.manageasy.com/request_offer.php3'
method='post' onSubmit='return checkform(this.form);'>\n");
print("<input type='hidden' name='offerPrice'
value='$offerPrice'>\n");
?>
Otherwise I really can't think why the janascript did not get executed.
Jack
jacky@activelifestyle.com
"Power is nothing without control
----- Original Message -----
From: Mark Maggelet <maggelet@mminternet.com>
To: <jacky@activelifestyle.com>; <php-general@lists.php.net>
Sent: Monday, December 04, 2000 4:00 AM
Subject: Re: [PHP] simple form validation
> On Mon, 4 Dec 2000 15:38:03 -0600, Jacky (jacky@activelifestyle.com)
> wrote:
> >Hi all,
> >I know this is perhaps very simple thing but would be pleased if
> >anyone can give me teh straight forward way. I need to validate a
> >form that not allowed the form to be submitted if there is any field
> >left blank. I would like to use javascript if that is possible. But
> >I get confused with how could I embed javascript to validate the
> >form as I am more familiar with ASP than PhP.
> >Jack
> >jacky@activelifestyle.com
> >"Power is nothing without control
>
> something like this:
> <script language="javascript">
> function checkfields() {
> for(i=0;i<this.form.length;i++){
> if(this.form.elements[i].value.length==0){
> alert("fill them all out!");
> return false;
> }
> }
> return true;
> }
> </script>
>
> <form name=form onsubmit="return checkfields();">
>
> - Mark
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>