apply_data()

apply_data( object[, **kw])

The apply_data() method of the PSPInstance object will get the parameters from form data sent as get or post and pass them to a given callable object.

It will pass only the parameters the callable is expecting. An instance of a PSPInstance object is available as the psp variable.

This script will use apply_data() to pass a date to a date validating function. It could be called like this:

http://my_server.tld/path/to/date_validate.psp?date=11-04-2006

<%
import time

# The parameter should have a default value to avoid
# an exception in case the parameter is not passed
def date_validate(date=None):
   if not date:
      return 'Date parameter is missing'

   # strptime() raises an exception if date is not in the given format
   try:
      time.strptime(date, '%m-%d-%Y')
   except ValueError:
      return 'Invalid date: "%s"' % date
   else:
      return 'Valid date: "%s"' % date 
#
%>
<html><body>
<%-- apply_data() will pass the received parameters to a callable  --%>
<p><%= psp.apply_data(date_validate) %></p>
</body></html>