I'm performing all my form validation in a class, and would like to be able to get the errors from the class to the rendered html. One approach I was thinking about was to create a global variable "c" that would store all the errors and to set them from within the class, as I still want the individual methods to return false when they fail. Here is some sample code:
class User():
def add(self):
#Check that e-mail has been completed
try:
#Validate e-mail address
if (isAddressValid(self.email)):
c.error = 'Invalid e-mail address'
return 0
except NameError:
c.error = 'No e-mail address specified'
return 0
Is there a better or preferred way to do this?
Thanks.