form validation: from php newbie
| From: | Jacky | Date: | Mon, 04 Dec 2000 23:05:11 +0000 |
| Subject: | form validation: from php newbie | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-28548@lists.php.net to get a copy of this message | ||
Sorry to post the same thing again. There were some helps came to me yet I
still not quite good enough to get my problem work out, perhaps need more
clear suggestions.
Allow me to make my situation clearer, I have the simple form in html but
using extension php3. The code looks something below. But when I run the
page, it never executed the javascript part once and still does the
submission as normal. What did I do wrong?
<html>
<head>
<script language="javascript">
var charexp = /./
function hasChar(str) {
return charexp.test(str);
}
function checkform() {
if (!hasChar(document.form.firstname.value)) {
alert("You must enter your first name");
form.firstname.focus();
return false;
}
if (!hasChar(document.form.lastname.value)) {
alert("You must enter your last name");
form.lastname.focus();
return false;
}
alert("Data valid");
return true;
}
</script>
</head>
<body>
<?
print("<form action='nextpage.php3 method='post onSubmit='return
checkform()'>\n")
print("<input type='hidden' name='offerPrice'
value='$offerPrice'>\n");
//this came from the previous page
?>
Firstname:
<input name="firstname">
Lastname:
<input name="lastname">
<input type=submit name="submit" value="submit">
</form>
</body>
</html>
Jack
jacky@activelifestyle.com
"Power is nothing without control
----- Original Message -----
From: <Lawrence.Sheed@dfait-maeci.gc.ca>
To: <jacky@activelifestyle.com>; <php-general@lists.php.net>
Sent: Monday, December 04, 2000 2:45 AM
Subject: RE: [PHP] simple form validation
> Javascript is client parsed - its in the html code you output.
> Either something like
>
> echo "<script><!-- javascript stuff here --></script>";
>
> or
>
> ?>
>
> <script>
> <!--
> javascript
>
> -->
> </script>
>
> <?php
>
> Would do (given the relevant javascript code).
>
> PHP is server side parsed. If you want to validate *after* the form post
> event, that might be better - because that will work with every client
> browser, as opposed to the big 2.
>
> -----Original Message-----
> From: Jacky [mailto:jacky@activelifestyle.com]
> Sent: December 5, 2000 05:38 AM
> To: php-general@lists.php.net
> Subject: [PHP] simple form validation
>
>
> 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
>
> --
> 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
>