RE: [PHP] presenting a failed form for re-entry.

From: Date: Thu, 07 Sep 2000 21:37:57 +0000
Subject: RE: [PHP] presenting a failed form for re-entry.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-15781@lists.php.net to get a copy of this message
> <input name='foo' value='<?=$foo;?>'> > <?=$mark['foo'];?> <br> > <input name='bar' value='<?=$bar;?>'> > <?=$mark['bar'];?> <br> huh? what does the <?=$bar;?> do? don't you mean <? echo $bar; ?> is = a shortcut for something? I've never seen that before... ////////////////////////////////////////////////////////////////////// oh, just another suggestion to this question, I do something like this: <?php $errstring = ""; if ($edit_demo_id == "") $errstring .= "You need to select a name to EDIT from the drop down list first.<BR>"; if ($demo_name == "") $errstring .= "You need to enter a demo name.<BR>"; ?> then at the top of the HTML output, I just <?php if ($errstring != "") echo "<FONT SIZE=+1 COLOR=#FF0000>".$errstring."</FONT>"; ?> then I don't have to highlight or do anything funky with any specific field, and the beauty is that it will just append all the errors together and dump them all out for any fields you check. dig? And even slicker is to use Javascript then the user can't submit erroneous data, and it saves wear on the server as PHP doesn't have to parse the form only to find out it's defective: -------------------------------------------------------------------------- <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript"> <!-- function checkFields() { with ( document.demoForm ) { if( edit_demo_id.value == "" ) { alert("You need to select a name to EDIT from the drop down list first."); edit_demo_id.focus(); edit_demo_id.select(); return false; } if( demo_name.value == "" ) { alert("You need to enter a demo name."); demo_name.focus(); demo_name.select(); return false; } } return true; } //--> </SCRIPT> <FORM Method="Post" NAME="demoForm"> <INPUT Name="edit_demo_id" Size="50" MAXLENGTH="50" Value='<?php echo $edit_demo_id;?>'> <INPUT Name="demo_name" Size="50" MAXLENGTH="50" Value='<?php echo $demo_name;?>'> <INPUT TYPE="SUBMIT" VALUE='SUBMIT' onClick="return checkFields();"> </FORM> -------------------------------------------------------------------------- I use both, for those people that may not have javascript enabled, but at least it'll catch like 90% of the people out there. http://daevid.com

« previous php.general (#15781) next »