# add_numbers form, version 1
# basic form, no real functionality

<html>
  <body>
    <form action="" method="post">
      <p>Enter two integers.</p>
      First: <input type="text" name="n1" value="" /><br />
      Second: <input type="text" name="n2" value="" /><br />
      <input type="submit" name="submit" value="Submit" />
    </form>
  </body>
</html>


# add_numbers form, version 2
# basic form, formcontroller enabled (but doesn't do much yet)


<html>
  <body>
    <form tal:attributes="action python:here.absolute_url()+'/'+template.id" 
      method="post">
        <input type="hidden" name="form.submitted" value="1" />
        <p>Enter two integers.</p>
        First: <input type="text" name="n1" value="" /><br />
        Second: <input type="text" name="n2" value="" /><br />
        <input type="submit" name="submit" value="Submit" />
    </form>
  </body>
</html>



# add_numbers_validate

if not n1:
   state.setError('n1', 'Please enter a value')
else:
   try:
      n1 = int(n1)
   except (ValueError, TypeError):
      state.setError('n1', 'Please enter an integer')

if not n2:
   state.setError('n2', 'Please enter a value')
else:
   try:
      n2 = int(n2)
   except (ValueError, TypeError):
      state.setError('n2', 'Please enter an integer')

if state.getErrors():  # an error has occurred
   state.setStatus('failure')  # set status to failure
   return state.set(portal_status_message='Please correct the errors shown')

return state # no errors -- always return the state object


# add_numbers form, version 3
# basic form, formcontroller enabled, displays error messages

<html>
  <body>
    <p tal:define="msg request/portal_status_message|nothing" tal:condition="msg"
       tal:content="msg" />
    <form 
      tal:define="errors options/state/getErrors"
      tal:attributes="action python:here.absolute_url()+'/'+template.id" 
      method="put">
        <input type="hidden" name="form.submitted" value="1" />
        <p>Enter two integers.</p>
        <p tal:define="err errors/n1|nothing" tal:condition="err"
           tal:content="err" />
        First: <input type="text" name="n1" tal:attributes="value request/n1|nothing" /><br />
        <p tal:define="err errors/n2|nothing" tal:condition="err"
           tal:content="err" />
        Second: <input type="text" name="n2" tal:attributes="value request/n2|nothing" /><br />
        <input type="submit" name="submit" value="Submit" />
    </form>
  </body>
</html>


# add_numbers_results

<html>
  <head>
    <title tal:content="template/title">The title</title>
  </head>
  <body>
    <p tal:content="request/n" />
  </body>
</html>