RE: form validation: from php newbie

From: Date: Wed, 06 Dec 2000 08:43:00 +0000
Subject: RE: form validation: from php newbie
Groups: php.general 
Request: Send a blank email to php-general+get-28859@lists.php.net to get a copy of this message
As far as I can see you're not calling the function at all. The action of the form still goes to nextpage.php3. A form action submits the form back to server side and hence has to call another page (please someone correct me if I'm wrong). To check the form on client side, you would need to use the OnClick event of the button. I'm not sure about event orders here, you might need to make the button a simple pushbutton rather than a submit button and call the next page from within the checking function. Tim Ward Senior Systems Engineer Please refer to the following disclaimer in respect of this message: http://www.stivesdirect.com/e-mail-disclaimer.html > -----Original Message----- > From: Jacky [mailto:jacky@activelifestyle.com] > Sent: 04 December 2000 23:05 > To: php-general@lists.php.net > Subject: form validation: from php newbie > > > 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 > > > >

« previous php.general (#28859) next »