RE: [PHP] Form validation of dynamically generated forms?

From: Date: Mon, 28 Aug 2000 20:58:43 +0000
Subject: RE: [PHP] Form validation of dynamically generated forms?
Groups: php.general 
Request: Send a blank email to php-general+get-14007@lists.php.net to get a copy of this message
If it makes no difference (and I'm just playing devil's advocate here -- it should NOT make a difference), can you tell me why this code does not work in NS: // dynamically generated <script Language="JavaScript"> <!-- function Form_Validator() { if (document.myForm.QUANTITY2.value == '') { alert("You must enter a value for the Quantity field.") document.myForm.QUANTITY2.focus(); return (false); } if (document.myForm.DOCKDATE2.value == '') { alert("You must enter a value for the Dock Date field.") document.myForm.DOCKDATE2.focus(); return (false); } return (true); } //--> </script> works, and this code does? // static <script Language="JavaScript"> <!-- function Form_Validator() { if (document.myForm.QUANTITY2.value == '') { alert("You must enter a value for the Quantity field.") document.myForm.QUANTITY2.focus(); return (false); } if (document.myForm.DOCKDATE2.value == '') { alert("You must enter a value for the Dock Date field.") document.myForm.DOCKDATE2.focus(); return (false); } return (true); } //--> </script> Hint: they are exactly the same. It's driving me NUTS. The code is EXACTLY THE SAME. I'm wondering if it's something with the way NS handles it, because I can't view the source of it in NS since it's being POSTed.. IE lets me though, and that's how I know the content of the PHP-generated Javascript. (btw, I put the semicolon after the alert fields.. thanks, but made no difference.. good to fix though) Chad -----Original Message----- From: D. Meehan [mailto:davem@nxg2.com] Sent: Monday, August 28, 2000 4:57 PM To: Chad Day Cc: php-general@lists.php.net Subject: Re: [PHP] Form validation of dynamically generated forms? It makes no difference whether the javascript was placed in a static html file, or if it was created with a server side scripting language such as PHP. Try checking your javascript syntax (hint: alert statements are terminated by a semicolon). It's things like this that can make netscape react differently to javascript than IE does. ----- Original Message ----- From: Chad Day <cday@beachassociates.com> To: 'Michael Packer' <pac@stingrayboats.com>; <php-general@lists.php.net> Sent: Monday, August 28, 2000 4:36 PM Subject: RE: [PHP] Form validation of dynamically generated forms? > I don't think that's the case. > > I just took some of the dynamically created code, and put it in a regular > html file, and renamed the dynamic input name boxes to match the script. > > And it worked. > > Somewhere along the way of dynamically generating it, it's NOT working in > NS. > > THIS worked: > > <html> > <head> > </head> > <body> > <script Language="JavaScript"> > <!-- > function Form_Validator() { > if (document.myForm.QUANTITY2.value == '') { > alert("You must enter a value for the Quantity > field.") > document.myForm.QUANTITY2.focus(); > return (false); > } > if (document.myForm.DOCKDATE2.value == '') { > alert("You must enter a value for the Dock Date > field.") > document.myForm.DOCKDATE2.focus(); > return (false); > } > return (true); > } > file://--> > </script> > <form name="myForm" action="testform.php" > onsubmit="Form_Validator();"> > <input type="text" name="QUANTITY2"> > <input type="text" name="DOCKDATE2"> > <input type="submit"> > </form> > </body> > </html> > > The dynamic code in my earlier email does NOT work, even though it outputs > that exact same javascript as above. > > Why? > > Chad > > -----Original Message----- > From: Michael Packer [mailto:pac@stingrayboats.com] > Sent: Monday, August 28, 2000 4:32 PM > To: Chad Day; php-general@lists.php.net > Subject: RE: [PHP] Form validation of dynamically generated forms? > > > if the JS code works under IE then it has nothing to do with PHP. PHP is > finished once the page is created. if the page is created the way you want > it (look at source) then PHP isn't related to this. Just because you create > the PHP doesn't mean the problem is PHP. > > i can show you lots of JS that works fine under IE and doesn't work under > NS...it's because NS doesn't support all of JS and IE has added lots of JS > stuff that really isn't in the standard (if you can even call what's out > there a standard). > > > > > -----Original Message----- > > From: Chad Day [mailto:cday@beachassociates.com] > > Sent: Monday, August 28, 2000 4:30 PM > > To: 'php-general@lists.php.net' > > Subject: RE: [PHP] Form validation of dynamically generated forms? > > > > > > No answers yet.. I've been searching around some archives, and found this: > > > > >I was not clear in my earlier email. The javascript function is not > > >written inside PHP tags. It is actually an included file. I > > >attempted this and it won't work. Thanks though. > > >MN > > > > which is not directly related to what I'm doing, but is still javascript > > written in PHP. > > > > I've had my javascript code looked over, and either people have told me 1) > > it should work or 2) not replied. Only works in IE, not NS. > > > > Is this a PHP problem? I at least want to get it narrowed down > > to that so I > > can explore other solutions. > > > > Chad > > -----Original Message----- > > From: Chad Day [mailto:cday@beachassociates.com] > > Sent: Monday, August 28, 2000 12:19 PM > > To: 'php-general@lists.php.net' > > Subject: [PHP] Form validation of dynamically generated forms? > > > > > > Having some trouble with this one.. trying to get form validation working > > on dynamically generated PHP forms.. if there's a code snippet out there > > that would help with what I have below, I would appreciate a link.. or if > > anyone here knows JS (I realize this is not a JS list), please drop me a > > line privately if you see the bug below. > > > > I tried writing some Javascript in PHP, and it works great in > > IE.. but in NS > > it dies. Returns a form has no properties error, and does not check for > > validation. > > > > echo "\n\n<script Language=\"JavaScript\">\n"; > > echo "<!--\n"; > > echo "function Form_Validator() {\n"; > > > > for ($x = 0; $x <= $MAX; $x++) { > > if((isset($ORDER[$x])) && ($ORDER[$x] == "checked")) { // loop > > through the array to get the values of the boxes we need to print > > out/validate > > > > echo "\t\tif (document.myForm.QUANTITY$x.value == '') {\n"; > > echo "\t\t\talert(\"You must enter a value for the Quantity > > field.\")\n"; > > echo "\t\t\tdocument.myForm.QUANTITY$x.focus();\n"; > > echo "\t\t\treturn (false);\n"; > > echo "\t\t}\n"; > > > > echo "\t\tif (document.myForm.DOCKDATE$x.value == '') {\n"; > > echo "\t\t\talert(\"You must enter a value for the Dock Date > > field.\")\n"; > > echo "\t\t\tdocument.myForm.DOCKDATE$x.focus();\n"; > > echo "\t\t\treturn (false);\n"; > > echo "\t\t}\n"; > > > > } > > } > > > > echo "\treturn (true);\n"; > > echo "}\n"; > > echo "file://-->\n"; > > echo "</script>\n"; > > > > > > I've looked around at form validation scripts for PHP, but I haven't seen > > anything that would really work for dynamically generated stuff without > > extensive modifying, which is probably beyond my skill level at > > this point. > > Are there any scripts out there that do this, or does anyone know what is > > wrong with my above code? The thing that annoys me is I use PHP generated > > javascript elsewhere in the site for form validation, and it works fine.. > > but those name boxes are static, not dynamic.. I don't know if that's the > > problem or not. > > Chad Day > > Beach Associates > > > > When I speak german... I think german in my head... but like...Do skript > > kiddies see a w40l3 8uncha 1's and 0's and 3's and 4's and 7's in > > their > > h34d'5 w43n t43y R +a1k1n6 ? -- SirStanley > > > > > > -- > > 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 > > > > -- > > 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 > > > > -- > 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 > -- 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 (#14007) next »