close Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Changes between Version 4 and Version 5 of FormProcessing


Ignore:
Timestamp:
Jul 1, 2008, 9:24:32 PM (16 years ago)
Author:
cmlenz
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • FormProcessing

    v4 v5  
    1111class LinkForm(Form):
    1212    username = TextValidator(required=True)
    13     url = TextValidator(required=True)
     13    url = TextValidator(required=True, pattern=r'^https?://')
    1414    title = TextValidator(required=True)
    1515
     
    1919    if request.method == 'POST':
    2020        if 'cancel' in request.POST:
    21             redirect_to('index')
     21            redirect_to('home')
    2222        if form.validate(request.POST):
    23             # Form is valid, store data int the database
     23            # Form is valid, store data into the database
    2424            link = Link(**form.data)
    2525            link.store(app.db)
     
    3232 * The form submission is protected against Cross-Site Request Forgery (CSRF) attacks, by adding a form token both as a cookie, and as a hidden form input field.
    3333
     34== HTML Forms in Templates ==
     35
     36Diva does not generate HTML markup for your forms automatically. The `diva.forms` package is only concerned with the form data, not the rendering of individual form elements and how they assembled into the larger form.
     37
     38For the form defined above, a simple template might contain something like this:
     39
     40{{{
     41#!genshi
     42<form action="" method="post">
     43  <p>
     44    <label>Your name: <input type="text" name="username" /></label>
     45    <span py:if="'username' in errors" class="error">${errors.username}</span>
     46  </p><p>
     47    <label>Link URL: <input type="text" name="url" /></label>
     48    <span py:if="'url' in errors" class="error">${errors.url}</span>
     49  </p><p>
     50    <label>Title: <input type="text" name="title" /></label>
     51    <span py:if="'title' in errors" class="error">${errors.title}</span>
     52  </p>
     53  <hr />
     54  <p>
     55    <input type="submit" />
     56  </p>
     57</form>
     58}}}
     59
     60Note that while you don't need to manually take care of filling in the form values, you do have to explicitly add any error messages that need to be displayed after a failed validation.
     61
    3462== API Documentation ==
    3563