Jump to content

Archived

This topic is now archived and is closed to further replies.

NoPHPPhD

How to check if field is empty before submit

Recommended Posts

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.... :-\

[code]
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");
[/code]

Share this post


Link to post
Share on other sites
You can try using [b]isset[/b], sorry I doesn't have the time to write out examples.

Share this post


Link to post
Share on other sites
You could do something like....

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

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

Share this post


Link to post
Share on other sites
This site http://www.php-mysql-tutorial.com/form-validation-with-php.php  has some info on client-side and server-side validation for forms. Might be of some help.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.