I am able to extract the form field data, but I am NOT able to Put a check / validate the information to see if The field is not empty.
I am writing it in Apache+mod_wsgi, browser FF, Python 2.6, Ubuntu 10.04 64bit
The Following is the sample code where web form field data is read.This is where i need to put a check, whether if this field is EMPTY or NOT. If empty ,a default_error string for specific field, go back and fill in the data. Till then "Save" ( or "Print & Save") DOES NOT show.
state = form.getvalue('state')
nameDistrict = form.getvalue('district')
dist_code = form.getvalue('Dcode')
html += 'State :' + str(state)
html += 'District Name :' + str(nameDistrict)
html += 'District Code :' + str(dist_code)
The following is one way I was trying, nAdA. :(
def val(dict, key, default_str):
value = dict.get(key, default_str)
if value == '':
return default_str
else:
return value
second attempt
if state == ' ' :
return 'Please Enter the State Name'
else :
return state
another trial was
try:
state = form.getvalue('state')
except ValueError:
'Please Enter the state Name'
No luck.
Please show by some examples by which I can put the check.
Thanks