[[! def calculate(self, api, x): from spyceException import HandlerError try: x = float(x) except ValueError: raise HandlerError('Value', 'Please input a number') if x < 0: raise HandlerError('Value', 'Cannot take the square root of negative numbers!') self.result = x ** 0.5 ]] <spy:parent title="Active Handler Validation" /> <f:form> <f:text name="x" default="-1" label="Value:" /> <f:submit handler="self.calculate" value="Square root" /> </f:form> <p> Result: [[= hasattr(self, 'result') and self.result or '(no result yet)' ]] </p>