Jump to content


Photo

How to check if field is empty before submit


  • Please log in to reply
3 replies to this topic

#1 NoPHPPhD

NoPHPPhD
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 30 October 2006 - 12:28 AM

I would like to make sure that "Quantity" is > zero when this is submitted.
If it is not, I would like to just redisplay the same form.
What do I have to do? Probably very simple, just not searching for the right term.... :-\

print("<FORM>\n");
print("<FORM ACTION=\"AddRecord.php\" METHOD=\"GET\">\n");
print("<INPUT TYPE=\"TEXT\" NAME=\"Quantity\">\n");
print("<INPUT TYPE=\"HIDDEN\" NAME=\"NBDno\" VALUE = '$pickedNBDno' >\n"); 

print("<SELECT NAME=\"Measure\">\n");	
	while($row = mysql_fetch_object($dbResult))
		{
		print("<OPTION VALUE=\"{$row->WeightID}\"");
		print(">{$row->Description}\n");
		}
		print("</SELECT>\n");

print("<INPUT TYPE=\"submit\">\n");	
print("</FORM>\n");


#2 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 30 October 2006 - 12:49 AM

You can try using isset, sorry I doesn't have the time to write out examples.

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#3 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 30 October 2006 - 12:52 AM

You could do something like....

if (isset($_GET['Quantity']) && $_GET['Quantity'] > 0) {
  // do action.
}

Of course this doesn't check the field until after submission (php cant), you would need to use Javascript to achieve that.

#4 twofivethreetwo

twofivethreetwo
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 30 October 2006 - 03:04 AM

This site http://www.php-mysql...n-with-php.php  has some info on client-side and server-side validation for forms. Might be of some help.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users