OUI

7.8 How can I prevent a form from having empty fields?

In most cases you want to make sure that a user actually enters something into input fields and not just leave them blank. This can best be done on the server side with a script language command checking for the length of the contents of the variable in question, but it can also be done directly in WML.

In WML this is done by using the correct formatting codes, or if that's not supported, adding a parameter called emptyok=false to the input tag. Note that it only means that the user cannot force the input to be blank. If you leave out the value="something" parameter or put value="" the user can still send empty fields.

The following line will accept any value to the "username" field, even if the user clears the field completely. He will be able to return from input mode, even if the field contains nothing.

  <input name="username" type="text" value="Enter something" format="*M"/>

The following line will accept any value to the "username" field, except if the user clears the field completely. He will not be able to return from input mode until the field contains something.

  <input name="username" type="text" value="Enter something" format="M*m"/>

However, the above applies to most browsers. On Nokia 7110, the emptyok parameter must be used to get the same effect:

  <input name="username" type="text" value="Enter something" format="*M" emptyok="false"/>
[ Main ]   [ 07 - Making it look fancy ]