Jump to content

How to check if field is empty before submit


NoPHPPhD

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]
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.