Ticket #3512: html_class4.diff

File html_class4.diff, 93.9 KB (added by SmileyChris, 8 years ago)

fixing bug in previous patch, adding tests and fixing docs

  • django/newforms/forms.py

     
    107107        """
    108108        return self.prefix and ('%s-%s' % (self.prefix, field_name)) or field_name
    109109
    110     def _html_output(self, normal_row, error_row, row_ender, help_text_html, errors_on_separate_row):
     110    def _html_output(self, normal_row, error_row, row_ender, help_text_html, errors_on_separate_row, html_class_list=None):
    111111        "Helper function for outputting HTML. Used by as_table(), as_ul(), as_p()."
    112112        top_errors = self.non_field_errors() # Errors that should be displayed above all fields.
    113113        output, hidden_fields = [], []
     114        html_class_list = html_class_list or []
    114115        for name, field in self.fields.items():
    115116            bf = BoundField(self, field, name)
    116117            bf_errors = ErrorList([escape(error) for error in bf.errors]) # Escape and cache in local variable.
     
    119120                    top_errors.extend(['(Hidden field %s) %s' % (name, e) for e in bf_errors])
    120121                hidden_fields.append(unicode(bf))
    121122            else:
     123                class_list = list(html_class_list) # A fresh list for each loop.
     124                if bf_errors:
     125                    class_list.append('error')
     126                if bf.field.required:
     127                    class_list.append('required')
     128                if class_list:
     129                    html_class = ' class="%s"' % ' '.join(class_list)
     130                else:
     131                    html_class = ''
    122132                if errors_on_separate_row and bf_errors:
    123133                    output.append(error_row % bf_errors)
    124134                label = bf.label and bf.label_tag(escape(bf.label + ':')) or ''
     
    126136                    help_text = help_text_html % field.help_text
    127137                else:
    128138                    help_text = u''
    129                 output.append(normal_row % {'errors': bf_errors, 'label': label, 'field': unicode(bf), 'help_text': help_text})
     139                output.append(normal_row % {'errors': bf_errors, 'label': label, 'field': unicode(bf), 'help_text': help_text, 'html_class': html_class})
    130140        if top_errors:
    131141            output.insert(0, error_row % top_errors)
    132142        if hidden_fields: # Insert any hidden fields in the last row.
     
    141151
    142152    def as_table(self):
    143153        "Returns this form rendered as HTML <tr>s -- excluding the <table></table>."
    144         return self._html_output(u'<tr><th>%(label)s</th><td>%(errors)s%(field)s%(help_text)s</td></tr>', u'<tr><td colspan="2">%s</td></tr>', '</td></tr>', u'<br />%s', False)
     154        return self._html_output(u'<tr%(html_class)s><th>%(label)s</th><td>%(errors)s%(field)s%(help_text)s</td></tr>', u'<tr><td colspan="2">%s</td></tr>', '</td></tr>', u'<br />%s', False)
    145155
    146156    def as_ul(self):
    147157        "Returns this form rendered as HTML <li>s -- excluding the <ul></ul>."
    148         return self._html_output(u'<li>%(errors)s%(label)s %(field)s%(help_text)s</li>', u'<li>%s</li>', '</li>', u' %s', False)
     158        return self._html_output(u'<li%(html_class)s>%(errors)s%(label)s %(field)s%(help_text)s</li>', u'<li>%s</li>', '</li>', u' %s', False)
    149159
    150160    def as_p(self):
    151161        "Returns this form rendered as HTML <p>s."
    152         return self._html_output(u'<p>%(label)s %(field)s%(help_text)s</p>', u'<p>%s</p>', '</p>', u' %s', True)
     162        return self._html_output(u'<p%(html_class)s>%(label)s %(field)s%(help_text)s</p>', u'<p>%s</p>', '</p>', u' %s', True)
    153163
    154164    def non_field_errors(self):
    155165        """
  • docs/newforms.txt

     
    293293
    294294    >>> f = ContactForm()
    295295    >>> print f
    296     <tr><th><label for="id_subject">Subject:</label></th><td><input id="id_subject" type="text" name="subject" maxlength="100" /></td></tr>
    297     <tr><th><label for="id_message">Message:</label></th><td><input type="text" name="message" id="id_message" /></td></tr>
    298     <tr><th><label for="id_sender">Sender:</label></th><td><input type="text" name="sender" id="id_sender" /></td></tr>
    299     <tr><th><label for="id_cc_myself">Cc myself:</label></th><td><input type="checkbox" name="cc_myself" id="id_cc_myself" /></td></tr>
     296    <tr class="required"><th><label for="id_subject">Subject:</label></th><td><input id="id_subject" type="text" name="subject" maxlength="100" /></td></tr>
     297    <tr class="required"><th><label for="id_message">Message:</label></th><td><input type="text" name="message" id="id_message" /></td></tr>
     298    <tr class="required"><th><label for="id_sender">Sender:</label></th><td><input type="text" name="sender" id="id_sender" /></td></tr>
     299    <tr class="required"><th><label for="id_cc_myself">Cc myself:</label></th><td><input type="checkbox" name="cc_myself" id="id_cc_myself" /></td></tr>
    300300
    301301If the form is bound to data, the HTML output will include that data
    302302appropriately. For example, if a field is represented by an
     
    310310    ...         'cc_myself': True}
    311311    >>> f = ContactForm(data)
    312312    >>> print f
    313     <tr><th><label for="id_subject">Subject:</label></th><td><input id="id_subject" type="text" name="subject" maxlength="100" value="hello" /></td></tr>
    314     <tr><th><label for="id_message">Message:</label></th><td><input type="text" name="message" id="id_message" value="Hi there" /></td></tr>
    315     <tr><th><label for="id_sender">Sender:</label></th><td><input type="text" name="sender" id="id_sender" value="foo@example.com" /></td></tr>
    316     <tr><th><label for="id_cc_myself">Cc myself:</label></th><td><input type="checkbox" name="cc_myself" id="id_cc_myself" checked="checked" /></td></tr>
     313    <tr class="required"><th><label for="id_subject">Subject:</label></th><td><input id="id_subject" type="text" name="subject" maxlength="100" value="hello" /></td></tr>
     314    <tr class="required"><th><label for="id_message">Message:</label></th><td><input type="text" name="message" id="id_message" value="Hi there" /></td></tr>
     315    <tr class="required"><th><label for="id_sender">Sender:</label></th><td><input type="text" name="sender" id="id_sender" value="foo@example.com" /></td></tr>
     316    <tr class="required"><th><label for="id_cc_myself">Cc myself:</label></th><td><input type="checkbox" name="cc_myself" id="id_cc_myself" checked="checked" /></td></tr>
    317317
    318318This default output is a two-column HTML table, with a ``<tr>`` for each field.
    319319Notice the following:
     
    354354
    355355    >>> f = ContactForm()
    356356    >>> f.as_p()
    357     u'<p><label for="id_subject">Subject:</label> <input id="id_subject" type="text" name="subject" maxlength="100" /></p>\n<p><label for="id_message">Message:</label> <input type="text" name="message" id="id_message" /></p>\n<p><label for="id_sender">Sender:</label> <input type="text" name="sender" id="id_sender" /></p>\n<p><label for="id_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_cc_myself" /></p>'
     357    u'<p class="required"><label for="id_subject">Subject:</label> <input id="id_subject" type="text" name="subject" maxlength="100" /></p>\n<p class="required"><label for="id_message">Message:</label> <input type="text" name="message" id="id_message" /></p>\n<p class="required"><label for="id_sender">Sender:</label> <input type="text" name="sender" id="id_sender" /></p>\n<p class="required"><label for="id_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_cc_myself" /></p>'
    358358    >>> print f.as_p()
    359     <p><label for="id_subject">Subject:</label> <input id="id_subject" type="text" name="subject" maxlength="100" /></p>
    360     <p><label for="id_message">Message:</label> <input type="text" name="message" id="id_message" /></p>
    361     <p><label for="id_sender">Sender:</label> <input type="text" name="sender" id="id_sender" /></p>
    362     <p><label for="id_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_cc_myself" /></p>
     359    <p class="required"><label for="id_subject">Subject:</label> <input id="id_subject" type="text" name="subject" maxlength="100" /></p>
     360    <p class="required"><label for="id_message">Message:</label> <input type="text" name="message" id="id_message" /></p>
     361    <p class="required"><label for="id_sender">Sender:</label> <input type="text" name="sender" id="id_sender" /></p>
     362    <p class="required"><label for="id_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_cc_myself" /></p>
    363363
    364364``as_ul()``
    365365~~~~~~~~~~~
     
    370370
    371371    >>> f = ContactForm()
    372372    >>> f.as_ul()
    373     u'<li><label for="id_subject">Subject:</label> <input id="id_subject" type="text" name="subject" maxlength="100" /></li>\n<li><label for="id_message">Message:</label> <input type="text" name="message" id="id_message" /></li>\n<li><label for="id_sender">Sender:</label> <input type="text" name="sender" id="id_sender" /></li>\n<li><label for="id_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_cc_myself" /></li>'
     373    u'<li class="required"><label for="id_subject">Subject:</label> <input id="id_subject" type="text" name="subject" maxlength="100" /></li>\n<li class="required"><label for="id_message">Message:</label> <input type="text" name="message" id="id_message" /></li>\n<li class="required"><label for="id_sender">Sender:</label> <input type="text" name="sender" id="id_sender" /></li>\n<li class="required"><label for="id_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_cc_myself" /></li>'
    374374    >>> print f.as_ul()
    375     <li><label for="id_subject">Subject:</label> <input id="id_subject" type="text" name="subject" maxlength="100" /></li>
    376     <li><label for="id_message">Message:</label> <input type="text" name="message" id="id_message" /></li>
    377     <li><label for="id_sender">Sender:</label> <input type="text" name="sender" id="id_sender" /></li>
    378     <li><label for="id_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_cc_myself" /></li>
     375    <li class="required"><label for="id_subject">Subject:</label> <input id="id_subject" type="text" name="subject" maxlength="100" /></li>
     376    <li class="required"><label for="id_message">Message:</label> <input type="text" name="message" id="id_message" /></li>
     377    <li class="required"><label for="id_sender">Sender:</label> <input type="text" name="sender" id="id_sender" /></li>
     378    <li class="required"><label for="id_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_cc_myself" /></li>
    379379
    380380``as_table()``
    381381~~~~~~~~~~~~~~
     
    386386
    387387    >>> f = ContactForm()
    388388    >>> f.as_table()
    389     u'<tr><th><label for="id_subject">Subject:</label></th><td><input id="id_subject" type="text" name="subject" maxlength="100" /></td></tr>\n<tr><th><label for="id_message">Message:</label></th><td><input type="text" name="message" id="id_message" /></td></tr>\n<tr><th><label for="id_sender">Sender:</label></th><td><input type="text" name="sender" id="id_sender" /></td></tr>\n<tr><th><label for="id_cc_myself">Cc myself:</label></th><td><input type="checkbox" name="cc_myself" id="id_cc_myself" /></td></tr>'
     389    u'<tr class="required"><th><label for="id_subject">Subject:</label></th><td><input id="id_subject" type="text" name="subject" maxlength="100" /></td></tr>\n<tr class="required"><th><label for="id_message">Message:</label></th><td><input type="text" name="message" id="id_message" /></td></tr>\n<tr class="required"><th><label for="id_sender">Sender:</label></th><td><input type="text" name="sender" id="id_sender" /></td></tr>\n<tr class="required"><th><label for="id_cc_myself">Cc myself:</label></th><td><input type="checkbox" name="cc_myself" id="id_cc_myself" /></td></tr>'
    390390    >>> print f.as_table()
    391     <tr><th><label for="id_subject">Subject:</label></th><td><input id="id_subject" type="text" name="subject" maxlength="100" /></td></tr>
    392     <tr><th><label for="id_message">Message:</label></th><td><input type="text" name="message" id="id_message" /></td></tr>
    393     <tr><th><label for="id_sender">Sender:</label></th><td><input type="text" name="sender" id="id_sender" /></td></tr>
    394     <tr><th><label for="id_cc_myself">Cc myself:</label></th><td><input type="checkbox" name="cc_myself" id="id_cc_myself" /></td></tr>
     391    <tr class="required"><th><label for="id_subject">Subject:</label></th><td><input id="id_subject" type="text" name="subject" maxlength="100" /></td></tr>
     392    <tr class="required"><th><label for="id_message">Message:</label></th><td><input type="text" name="message" id="id_message" /></td></tr>
     393    <tr class="required"><th><label for="id_sender">Sender:</label></th><td><input type="text" name="sender" id="id_sender" /></td></tr>
     394    <tr class="required"><th><label for="id_cc_myself">Cc myself:</label></th><td><input type="checkbox" name="cc_myself" id="id_cc_myself" /></td></tr>
    395395
    396396Configuring HTML ``<label>`` tags
    397397~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     
    414414
    415415    >>> f = ContactForm(auto_id=False)
    416416    >>> print f.as_table()
    417     <tr><th>Subject:</th><td><input type="text" name="subject" maxlength="100" /></td></tr>
    418     <tr><th>Message:</th><td><input type="text" name="message" /></td></tr>
    419     <tr><th>Sender:</th><td><input type="text" name="sender" /></td></tr>
    420     <tr><th>Cc myself:</th><td><input type="checkbox" name="cc_myself" /></td></tr>
     417    <tr class="required"><th>Subject:</th><td><input type="text" name="subject" maxlength="100" /></td></tr>
     418    <tr class="required"><th>Message:</th><td><input type="text" name="message" /></td></tr>
     419    <tr class="required"><th>Sender:</th><td><input type="text" name="sender" /></td></tr>
     420    <tr class="required"><th>Cc myself:</th><td><input type="checkbox" name="cc_myself" /></td></tr>
    421421    >>> print f.as_ul()
    422     <li>Subject: <input type="text" name="subject" maxlength="100" /></li>
    423     <li>Message: <input type="text" name="message" /></li>
    424     <li>Sender: <input type="text" name="sender" /></li>
    425     <li>Cc myself: <input type="checkbox" name="cc_myself" /></li>
     422    <li class="required">Subject: <input type="text" name="subject" maxlength="100" /></li>
     423    <li class="required">Message: <input type="text" name="message" /></li>
     424    <li class="required">Sender: <input type="text" name="sender" /></li>
     425    <li class="required">Cc myself: <input type="checkbox" name="cc_myself" /></li>
    426426    >>> print f.as_p()
    427     <p>Subject: <input type="text" name="subject" maxlength="100" /></p>
    428     <p>Message: <input type="text" name="message" /></p>
    429     <p>Sender: <input type="text" name="sender" /></p>
    430     <p>Cc myself: <input type="checkbox" name="cc_myself" /></p>
     427    <p class="required">Subject: <input type="text" name="subject" maxlength="100" /></p>
     428    <p class="required">Message: <input type="text" name="message" /></p>
     429    <p class="required">Sender: <input type="text" name="sender" /></p>
     430    <p class="required">Cc myself: <input type="checkbox" name="cc_myself" /></p>
    431431
    432432If ``auto_id`` is set to ``True``, then the form output *will* include
    433433``<label>`` tags and will simply use the field name as its ``id`` for each form
     
    435435
    436436    >>> f = ContactForm(auto_id=True)
    437437    >>> print f.as_table()
    438     <tr><th><label for="subject">Subject:</label></th><td><input id="subject" type="text" name="subject" maxlength="100" /></td></tr>
    439     <tr><th><label for="message">Message:</label></th><td><input type="text" name="message" id="message" /></td></tr>
    440     <tr><th><label for="sender">Sender:</label></th><td><input type="text" name="sender" id="sender" /></td></tr>
    441     <tr><th><label for="cc_myself">Cc myself:</label></th><td><input type="checkbox" name="cc_myself" id="cc_myself" /></td></tr>
     438    <tr class="required"><th><label for="subject">Subject:</label></th><td><input id="subject" type="text" name="subject" maxlength="100" /></td></tr>
     439    <tr class="required"><th><label for="message">Message:</label></th><td><input type="text" name="message" id="message" /></td></tr>
     440    <tr class="required"><th><label for="sender">Sender:</label></th><td><input type="text" name="sender" id="sender" /></td></tr>
     441    <tr class="required"><th><label for="cc_myself">Cc myself:</label></th><td><input type="checkbox" name="cc_myself" id="cc_myself" /></td></tr>
    442442    >>> print f.as_ul()
    443     <li><label for="subject">Subject:</label> <input id="subject" type="text" name="subject" maxlength="100" /></li>
    444     <li><label for="message">Message:</label> <input type="text" name="message" id="message" /></li>
    445     <li><label for="sender">Sender:</label> <input type="text" name="sender" id="sender" /></li>
    446     <li><label for="cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="cc_myself" /></li>
     443    <li class="required"><label for="subject">Subject:</label> <input id="subject" type="text" name="subject" maxlength="100" /></li>
     444    <li class="required"><label for="message">Message:</label> <input type="text" name="message" id="message" /></li>
     445    <li class="required"><label for="sender">Sender:</label> <input type="text" name="sender" id="sender" /></li>
     446    <li class="required"><label for="cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="cc_myself" /></li>
    447447    >>> print f.as_p()
    448     <p><label for="subject">Subject:</label> <input id="subject" type="text" name="subject" maxlength="100" /></p>
    449     <p><label for="message">Message:</label> <input type="text" name="message" id="message" /></p>
    450     <p><label for="sender">Sender:</label> <input type="text" name="sender" id="sender" /></p>
    451     <p><label for="cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="cc_myself" /></p>
     448    <p class="required"><label for="subject">Subject:</label> <input id="subject" type="text" name="subject" maxlength="100" /></p>
     449    <p class="required"><label for="message">Message:</label> <input type="text" name="message" id="message" /></p>
     450    <p class="required"><label for="sender">Sender:</label> <input type="text" name="sender" id="sender" /></p>
     451    <p class="required"><label for="cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="cc_myself" /></p>
    452452
    453453If ``auto_id`` is set to a string containing the format character ``'%s'``,
    454454then the form output will include ``<label>`` tags, and will generate ``id``
     
    458458
    459459    >>> f = ContactForm(auto_id='id_for_%s')
    460460    >>> print f.as_table()
    461     <tr><th><label for="id_for_subject">Subject:</label></th><td><input id="id_for_subject" type="text" name="subject" maxlength="100" /></td></tr>
    462     <tr><th><label for="id_for_message">Message:</label></th><td><input type="text" name="message" id="id_for_message" /></td></tr>
    463     <tr><th><label for="id_for_sender">Sender:</label></th><td><input type="text" name="sender" id="id_for_sender" /></td></tr>
    464     <tr><th><label for="id_for_cc_myself">Cc myself:</label></th><td><input type="checkbox" name="cc_myself" id="id_for_cc_myself" /></td></tr>
     461    <tr class="required"><th><label for="id_for_subject">Subject:</label></th><td><input id="id_for_subject" type="text" name="subject" maxlength="100" /></td></tr>
     462    <tr class="required"><th><label for="id_for_message">Message:</label></th><td><input type="text" name="message" id="id_for_message" /></td></tr>
     463    <tr class="required"><th><label for="id_for_sender">Sender:</label></th><td><input type="text" name="sender" id="id_for_sender" /></td></tr>
     464    <tr class="required"><th><label for="id_for_cc_myself">Cc myself:</label></th><td><input type="checkbox" name="cc_myself" id="id_for_cc_myself" /></td></tr>
    465465    >>> print f.as_ul()
    466     <li><label for="id_for_subject">Subject:</label> <input id="id_for_subject" type="text" name="subject" maxlength="100" /></li>
    467     <li><label for="id_for_message">Message:</label> <input type="text" name="message" id="id_for_message" /></li>
    468     <li><label for="id_for_sender">Sender:</label> <input type="text" name="sender" id="id_for_sender" /></li>
    469     <li><label for="id_for_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_for_cc_myself" /></li>
     466    <li class="required"><label for="id_for_subject">Subject:</label> <input id="id_for_subject" type="text" name="subject" maxlength="100" /></li>
     467    <li class="required"><label for="id_for_message">Message:</label> <input type="text" name="message" id="id_for_message" /></li>
     468    <li class="required"><label for="id_for_sender">Sender:</label> <input type="text" name="sender" id="id_for_sender" /></li>
     469    <li class="required"><label for="id_for_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_for_cc_myself" /></li>
    470470    >>> print f.as_p()
    471     <p><label for="id_for_subject">Subject:</label> <input id="id_for_subject" type="text" name="subject" maxlength="100" /></p>
    472     <p><label for="id_for_message">Message:</label> <input type="text" name="message" id="id_for_message" /></p>
    473     <p><label for="id_for_sender">Sender:</label> <input type="text" name="sender" id="id_for_sender" /></p>
    474     <p><label for="id_for_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_for_cc_myself" /></p>
     471    <p class="required"><label for="id_for_subject">Subject:</label> <input id="id_for_subject" type="text" name="subject" maxlength="100" /></p>
     472    <p class="required"><label for="id_for_message">Message:</label> <input type="text" name="message" id="id_for_message" /></p>
     473    <p class="required"><label for="id_for_sender">Sender:</label> <input type="text" name="sender" id="id_for_sender" /></p>
     474    <p class="required"><label for="id_for_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_for_cc_myself" /></p>
    475475
    476476If ``auto_id`` is set to any other true value -- such as a string that doesn't
    477477include ``%s`` -- then the library will act as if ``auto_id`` is ``True``.
     
    501501    ...         'cc_myself': True}
    502502    >>> f = ContactForm(data, auto_id=False)
    503503    >>> print f.as_table()
    504     <tr><th>Subject:</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="subject" maxlength="100" /></td></tr>
    505     <tr><th>Message:</th><td><input type="text" name="message" value="Hi there" /></td></tr>
    506     <tr><th>Sender:</th><td><ul class="errorlist"><li>Enter a valid e-mail address.</li></ul><input type="text" name="sender" value="invalid e-mail address" /></td></tr>
    507     <tr><th>Cc myself:</th><td><input checked="checked" type="checkbox" name="cc_myself" /></td></tr>
     504    <tr class="error required"><th>Subject:</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="subject" maxlength="100" /></td></tr>
     505    <tr class="required"><th>Message:</th><td><input type="text" name="message" value="Hi there" /></td></tr>
     506    <tr class="error required"><th>Sender:</th><td><ul class="errorlist"><li>Enter a valid e-mail address.</li></ul><input type="text" name="sender" value="invalid e-mail address" /></td></tr>
     507    <tr class="required"><th>Cc myself:</th><td><input checked="checked" type="checkbox" name="cc_myself" /></td></tr>
    508508    >>> print f.as_ul()
    509     <li><ul class="errorlist"><li>This field is required.</li></ul>Subject: <input type="text" name="subject" maxlength="100" /></li>
    510     <li>Message: <input type="text" name="message" value="Hi there" /></li>
    511     <li><ul class="errorlist"><li>Enter a valid e-mail address.</li></ul>Sender: <input type="text" name="sender" value="invalid e-mail address" /></li>
    512     <li>Cc myself: <input checked="checked" type="checkbox" name="cc_myself" /></li>
     509    <li class="error required"><ul class="errorlist"><li>This field is required.</li></ul>Subject: <input type="text" name="subject" maxlength="100" /></li>
     510    <li class="required">Message: <input type="text" name="message" value="Hi there" /></li>
     511    <li class="error required"><ul class="errorlist"><li>Enter a valid e-mail address.</li></ul>Sender: <input type="text" name="sender" value="invalid e-mail address" /></li>
     512    <li class="required">Cc myself: <input checked="checked" type="checkbox" name="cc_myself" /></li>
    513513    >>> print f.as_p()
    514514    <p><ul class="errorlist"><li>This field is required.</li></ul></p>
    515     <p>Subject: <input type="text" name="subject" maxlength="100" /></p>
    516     <p>Message: <input type="text" name="message" value="Hi there" /></p>
     515    <p class="error required">Subject: <input type="text" name="subject" maxlength="100" /></p>
     516    <p class="required">Message: <input type="text" name="message" value="Hi there" /></p>
    517517    <p><ul class="errorlist"><li>Enter a valid e-mail address.</li></ul></p>
    518     <p>Sender: <input type="text" name="sender" value="invalid e-mail address" /></p>
    519     <p>Cc myself: <input checked="checked" type="checkbox" name="cc_myself" /></p>
     518    <p class="error required">Sender: <input type="text" name="sender" value="invalid e-mail address" /></p>
     519    <p class="required">Cc myself: <input checked="checked" type="checkbox" name="cc_myself" /></p>
    520520
     521You will notice that each row which is required is given the HTML class name
     522``required`` and any row which the field did not pass validation receives the
     523``error`` class name.
     524
    521525More granular output
    522526~~~~~~~~~~~~~~~~~~~~
    523527
     
    587591    ...     priority = forms.CharField()
    588592    >>> f = ContactFormWithPriority(auto_id=False)
    589593    >>> print f.as_ul()
    590     <li>Subject: <input type="text" name="subject" maxlength="100" /></li>
    591     <li>Message: <input type="text" name="message" /></li>
    592     <li>Sender: <input type="text" name="sender" /></li>
    593     <li>Cc myself: <input type="checkbox" name="cc_myself" /></li>
    594     <li>Priority: <input type="text" name="priority" /></li>
     594    <li class="required">Subject: <input type="text" name="subject" maxlength="100" /></li>
     595    <li class="required">Message: <input type="text" name="message" /></li>
     596    <li class="required">Sender: <input type="text" name="sender" /></li>
     597    <li class="required">Cc myself: <input type="checkbox" name="cc_myself" /></li>
     598    <li class="required">Priority: <input type="text" name="priority" /></li>
    595599
    596600It's possible to subclass multiple forms, treating forms as "mix-ins." In this
    597601example, ``BeatleForm`` subclasses both ``PersonForm`` and ``InstrumentForm``
     
    607611    ...     haircut_type = CharField()
    608612    >>> b = BeatleForm(auto_id=False)
    609613    >>> print b.as_ul()
    610     <li>First name: <input type="text" name="first_name" /></li>
    611     <li>Last name: <input type="text" name="last_name" /></li>
    612     <li>Instrument: <input type="text" name="instrument" /></li>
    613     <li>Haircut type: <input type="text" name="haircut_type" /></li>
     614    <li class="required">First name: <input type="text" name="first_name" /></li>
     615    <li class="required">Last name: <input type="text" name="last_name" /></li>
     616    <li class="required">Instrument: <input type="text" name="instrument" /></li>
     617    <li class="required">Haircut type: <input type="text" name="haircut_type" /></li>
    614618
    615619Fields
    616620======
     
    717721    ...     comment = forms.CharField()
    718722    >>> f = CommentForm(auto_id=False)
    719723    >>> print f
    720     <tr><th>Your name:</th><td><input type="text" name="name" /></td></tr>
     724    <tr class="required"><th>Your name:</th><td><input type="text" name="name" /></td></tr>
    721725    <tr><th>Your Web site:</th><td><input type="text" name="url" /></td></tr>
    722     <tr><th>Comment:</th><td><input type="text" name="comment" /></td></tr>
     726    <tr class="required"><th>Comment:</th><td><input type="text" name="comment" /></td></tr>
    723727
    724728``initial``
    725729~~~~~~~~~~~
     
    736740    ...     comment = forms.CharField()
    737741    >>> f = CommentForm(auto_id=False)
    738742    >>> print f
    739     <tr><th>Name:</th><td><input type="text" name="name" value="Your name" /></td></tr>
    740     <tr><th>Url:</th><td><input type="text" name="url" value="http://" /></td></tr>
    741     <tr><th>Comment:</th><td><input type="text" name="comment" /></td></tr>
     743    <tr class="required"><th>Name:</th><td><input type="text" name="name" value="Your name" /></td></tr>
     744    <tr class="required"><th>Url:</th><td><input type="text" name="url" value="http://" /></td></tr>
     745    <tr class="required"><th>Comment:</th><td><input type="text" name="comment" /></td></tr>
    742746
    743747You may be thinking, why not just pass a dictionary of the initial values as
    744748data when displaying the form? Well, if you do that, you'll trigger validation,
     
    751755    >>> default_data = {'name': 'Your name', 'url': 'http://'}
    752756    >>> f = CommentForm(default_data, auto_id=False)
    753757    >>> print f
    754     <tr><th>Name:</th><td><input type="text" name="name" value="Your name" /></td></tr>
    755     <tr><th>Url:</th><td><ul class="errorlist"><li>Enter a valid URL.</li></ul><input type="text" name="url" value="http://" /></td></tr>
    756     <tr><th>Comment:</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="comment" /></td></tr>
     758    <tr class="required"><th>Name:</th><td><input type="text" name="name" value="Your name" /></td></tr>
     759    <tr class="required"><th>Url:</th><td><ul class="errorlist"><li>Enter a valid URL.</li></ul><input type="text" name="url" value="http://" /></td></tr>
     760    <tr class="required"><th>Comment:</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="comment" /></td></tr>
    757761
    758762This is why ``initial`` values are only displayed for unbound forms. For bound
    759763forms, the HTML output will use the bound data.
     
    797801    ...     cc_myself = forms.BooleanField()
    798802    >>> f = HelpTextContactForm(auto_id=False)
    799803    >>> print f.as_table()
    800     <tr><th>Subject:</th><td><input type="text" name="subject" maxlength="100" /><br />100 characters max.</td></tr>
    801     <tr><th>Message:</th><td><input type="text" name="message" /></td></tr>
    802     <tr><th>Sender:</th><td><input type="text" name="sender" /><br />A valid e-mail address, please.</td></tr>
    803     <tr><th>Cc myself:</th><td><input type="checkbox" name="cc_myself" /></td></tr>
     804    <tr class="required"><th>Subject:</th><td><input type="text" name="subject" maxlength="100" /><br />100 characters max.</td></tr>
     805    <tr class="required"><th>Message:</th><td><input type="text" name="message" /></td></tr>
     806    <tr class="required"><th>Sender:</th><td><input type="text" name="sender" /><br />A valid e-mail address, please.</td></tr>
     807    <tr class="required"><th>Cc myself:</th><td><input type="checkbox" name="cc_myself" /></td></tr>
    804808    >>> print f.as_ul()
    805     <li>Subject: <input type="text" name="subject" maxlength="100" /> 100 characters max.</li>
    806     <li>Message: <input type="text" name="message" /></li>
    807     <li>Sender: <input type="text" name="sender" /> A valid e-mail address, please.</li>
    808     <li>Cc myself: <input type="checkbox" name="cc_myself" /></li>
     809    <li class="required">Subject: <input type="text" name="subject" maxlength="100" /> 100 characters max.</li>
     810    <li class="required">Message: <input type="text" name="message" /></li>
     811    <li class="required">Sender: <input type="text" name="sender" /> A valid e-mail address, please.</li>
     812    <li class="required">Cc myself: <input type="checkbox" name="cc_myself" /></li>
    809813    >>> print f.as_p()
    810     <p>Subject: <input type="text" name="subject" maxlength="100" /> 100 characters max.</p>
    811     <p>Message: <input type="text" name="message" /></p>
    812     <p>Sender: <input type="text" name="sender" /> A valid e-mail address, please.</p>
    813     <p>Cc myself: <input type="checkbox" name="cc_myself" /></p>
     814    <p class="required">Subject: <input type="text" name="subject" maxlength="100" /> 100 characters max.</p>
     815    <p class="required">Message: <input type="text" name="message" /></p>
     816    <p class="required">Sender: <input type="text" name="sender" /> A valid e-mail address, please.</p>
     817    <p class="required">Cc myself: <input type="checkbox" name="cc_myself" /></p>
    814818
    815819Dynamic initial values
    816820----------------------
     
    831835    ...     comment = forms.CharField()
    832836    >>> f = CommentForm(initial={'name': 'your username'}, auto_id=False)
    833837    >>> print f
    834     <tr><th>Name:</th><td><input type="text" name="name" value="your username" /></td></tr>
    835     <tr><th>Url:</th><td><input type="text" name="url" /></td></tr>
    836     <tr><th>Comment:</th><td><input type="text" name="comment" /></td></tr>
     838    <tr class="required"><th>Name:</th><td><input type="text" name="name" value="your username" /></td></tr>
     839    <tr class="required"><th>Url:</th><td><input type="text" name="url" /></td></tr>
     840    <tr class="required"><th>Comment:</th><td><input type="text" name="comment" /></td></tr>
    837841    >>> f = CommentForm(initial={'name': 'another username'}, auto_id=False)
    838842    >>> print f
    839     <tr><th>Name:</th><td><input type="text" name="name" value="another username" /></td></tr>
    840     <tr><th>Url:</th><td><input type="text" name="url" /></td></tr>
    841     <tr><th>Comment:</th><td><input type="text" name="comment" /></td></tr>
     843    <tr class="required"><th>Name:</th><td><input type="text" name="name" value="another username" /></td></tr>
     844    <tr class="required"><th>Url:</th><td><input type="text" name="url" /></td></tr>
     845    <tr class="required"><th>Comment:</th><td><input type="text" name="comment" /></td></tr>
    842846
    843847Just like the ``initial`` parameter to ``Field``, these values are only
    844848displayed for unbound forms, and they're not used as fallback values if a
     
    855859    ...     comment = forms.CharField()
    856860    >>> f = CommentForm(initial={'name': 'instance'}, auto_id=False)
    857861    >>> print f
    858     <tr><th>Name:</th><td><input type="text" name="name" value="instance" /></td></tr>
    859     <tr><th>Url:</th><td><input type="text" name="url" /></td></tr>
    860     <tr><th>Comment:</th><td><input type="text" name="comment" /></td></tr>
     862    <tr class="required"><th>Name:</th><td><input type="text" name="name" value="instance" /></td></tr>
     863    <tr class="required"><th>Url:</th><td><input type="text" name="url" /></td></tr>
     864    <tr class="required"><th>Comment:</th><td><input type="text" name="comment" /></td></tr>
    861865
    862866More coming soon
    863867================
  • tests/regressiontests/forms/tests.py

     
    335335...     somechoice = ChoiceField(choices=chain((('', '-'*9),), [(thing['id'], thing['name']) for thing in things]))
    336336>>> f = SomeForm()
    337337>>> f.as_table()
    338 u'<tr><th><label for="id_somechoice">Somechoice:</label></th><td><select name="somechoice" id="id_somechoice">\n<option value="" selected="selected">---------</option>\n<option value="1">And Boom</option>\n<option value="2">One More Thing!</option>\n</select></td></tr>'
     338u'<tr class="required"><th><label for="id_somechoice">Somechoice:</label></th><td><select name="somechoice" id="id_somechoice">\n<option value="" selected="selected">---------</option>\n<option value="1">And Boom</option>\n<option value="2">One More Thing!</option>\n</select></td></tr>'
    339339>>> f.as_table()
    340 u'<tr><th><label for="id_somechoice">Somechoice:</label></th><td><select name="somechoice" id="id_somechoice">\n<option value="" selected="selected">---------</option>\n<option value="1">And Boom</option>\n<option value="2">One More Thing!</option>\n</select></td></tr>'
     340u'<tr class="required"><th><label for="id_somechoice">Somechoice:</label></th><td><select name="somechoice" id="id_somechoice">\n<option value="" selected="selected">---------</option>\n<option value="1">And Boom</option>\n<option value="2">One More Thing!</option>\n</select></td></tr>'
    341341>>> f = SomeForm({'somechoice': 2})
    342342>>> f.as_table()
    343 u'<tr><th><label for="id_somechoice">Somechoice:</label></th><td><select name="somechoice" id="id_somechoice">\n<option value="">---------</option>\n<option value="1">And Boom</option>\n<option value="2" selected="selected">One More Thing!</option>\n</select></td></tr>'
     343u'<tr class="required"><th><label for="id_somechoice">Somechoice:</label></th><td><select name="somechoice" id="id_somechoice">\n<option value="">---------</option>\n<option value="1">And Boom</option>\n<option value="2" selected="selected">One More Thing!</option>\n</select></td></tr>'
    344344
    345345You can also pass 'choices' to the constructor:
    346346>>> w = Select(choices=[(1, 1), (2, 2), (3, 3)])
     
    17681768Last name Lennon
    17691769Birthday 1940-10-9
    17701770>>> print p
    1771 <tr><th><label for="id_first_name">First name:</label></th><td><input type="text" name="first_name" value="John" id="id_first_name" /></td></tr>
    1772 <tr><th><label for="id_last_name">Last name:</label></th><td><input type="text" name="last_name" value="Lennon" id="id_last_name" /></td></tr>
    1773 <tr><th><label for="id_birthday">Birthday:</label></th><td><input type="text" name="birthday" value="1940-10-9" id="id_birthday" /></td></tr>
     1771<tr class="required"><th><label for="id_first_name">First name:</label></th><td><input type="text" name="first_name" value="John" id="id_first_name" /></td></tr>
     1772<tr class="required"><th><label for="id_last_name">Last name:</label></th><td><input type="text" name="last_name" value="Lennon" id="id_last_name" /></td></tr>
     1773<tr class="required"><th><label for="id_birthday">Birthday:</label></th><td><input type="text" name="birthday" value="1940-10-9" id="id_birthday" /></td></tr>
    17741774
    17751775Empty dictionaries are valid, too.
    17761776>>> p = Person({})
     
    17851785...
    17861786AttributeError: 'Person' object has no attribute 'clean_data'
    17871787>>> print p
    1788 <tr><th><label for="id_first_name">First name:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="first_name" id="id_first_name" /></td></tr>
    1789 <tr><th><label for="id_last_name">Last name:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="last_name" id="id_last_name" /></td></tr>
    1790 <tr><th><label for="id_birthday">Birthday:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="birthday" id="id_birthday" /></td></tr>
     1788<tr class="error required"><th><label for="id_first_name">First name:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="first_name" id="id_first_name" /></td></tr>
     1789<tr class="error required"><th><label for="id_last_name">Last name:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="last_name" id="id_last_name" /></td></tr>
     1790<tr class="error required"><th><label for="id_birthday">Birthday:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="birthday" id="id_birthday" /></td></tr>
    17911791>>> print p.as_table()
    1792 <tr><th><label for="id_first_name">First name:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="first_name" id="id_first_name" /></td></tr>
    1793 <tr><th><label for="id_last_name">Last name:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="last_name" id="id_last_name" /></td></tr>
    1794 <tr><th><label for="id_birthday">Birthday:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="birthday" id="id_birthday" /></td></tr>
     1792<tr class="error required"><th><label for="id_first_name">First name:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="first_name" id="id_first_name" /></td></tr>
     1793<tr class="error required"><th><label for="id_last_name">Last name:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="last_name" id="id_last_name" /></td></tr>
     1794<tr class="error required"><th><label for="id_birthday">Birthday:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="birthday" id="id_birthday" /></td></tr>
    17951795>>> print p.as_ul()
    1796 <li><ul class="errorlist"><li>This field is required.</li></ul><label for="id_first_name">First name:</label> <input type="text" name="first_name" id="id_first_name" /></li>
    1797 <li><ul class="errorlist"><li>This field is required.</li></ul><label for="id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></li>
    1798 <li><ul class="errorlist"><li>This field is required.</li></ul><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /></li>
     1796<li class="error required"><ul class="errorlist"><li>This field is required.</li></ul><label for="id_first_name">First name:</label> <input type="text" name="first_name" id="id_first_name" /></li>
     1797<li class="error required"><ul class="errorlist"><li>This field is required.</li></ul><label for="id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></li>
     1798<li class="error required"><ul class="errorlist"><li>This field is required.</li></ul><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /></li>
    17991799>>> print p.as_p()
    18001800<p><ul class="errorlist"><li>This field is required.</li></ul></p>
    1801 <p><label for="id_first_name">First name:</label> <input type="text" name="first_name" id="id_first_name" /></p>
     1801<p class="error required"><label for="id_first_name">First name:</label> <input type="text" name="first_name" id="id_first_name" /></p>
    18021802<p><ul class="errorlist"><li>This field is required.</li></ul></p>
    1803 <p><label for="id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></p>
     1803<p class="error required"><label for="id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></p>
    18041804<p><ul class="errorlist"><li>This field is required.</li></ul></p>
    1805 <p><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /></p>
     1805<p class="error required"><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /></p>
    18061806
    18071807If you don't pass any values to the Form's __init__(), or if you pass None,
    18081808the Form will be considered unbound and won't do any validation. Form.errors
     
    18191819...
    18201820AttributeError: 'Person' object has no attribute 'clean_data'
    18211821>>> print p
    1822 <tr><th><label for="id_first_name">First name:</label></th><td><input type="text" name="first_name" id="id_first_name" /></td></tr>
    1823 <tr><th><label for="id_last_name">Last name:</label></th><td><input type="text" name="last_name" id="id_last_name" /></td></tr>
    1824 <tr><th><label for="id_birthday">Birthday:</label></th><td><input type="text" name="birthday" id="id_birthday" /></td></tr>
     1822<tr class="required"><th><label for="id_first_name">First name:</label></th><td><input type="text" name="first_name" id="id_first_name" /></td></tr>
     1823<tr class="required"><th><label for="id_last_name">Last name:</label></th><td><input type="text" name="last_name" id="id_last_name" /></td></tr>
     1824<tr class="required"><th><label for="id_birthday">Birthday:</label></th><td><input type="text" name="birthday" id="id_birthday" /></td></tr>
    18251825>>> print p.as_table()
    1826 <tr><th><label for="id_first_name">First name:</label></th><td><input type="text" name="first_name" id="id_first_name" /></td></tr>
    1827 <tr><th><label for="id_last_name">Last name:</label></th><td><input type="text" name="last_name" id="id_last_name" /></td></tr>
    1828 <tr><th><label for="id_birthday">Birthday:</label></th><td><input type="text" name="birthday" id="id_birthday" /></td></tr>
     1826<tr class="required"><th><label for="id_first_name">First name:</label></th><td><input type="text" name="first_name" id="id_first_name" /></td></tr>
     1827<tr class="required"><th><label for="id_last_name">Last name:</label></th><td><input type="text" name="last_name" id="id_last_name" /></td></tr>
     1828<tr class="required"><th><label for="id_birthday">Birthday:</label></th><td><input type="text" name="birthday" id="id_birthday" /></td></tr>
    18291829>>> print p.as_ul()
    1830 <li><label for="id_first_name">First name:</label> <input type="text" name="first_name" id="id_first_name" /></li>
    1831 <li><label for="id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></li>
    1832 <li><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /></li>
     1830<li class="required"><label for="id_first_name">First name:</label> <input type="text" name="first_name" id="id_first_name" /></li>
     1831<li class="required"><label for="id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></li>
     1832<li class="required"><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /></li>
    18331833>>> print p.as_p()
    1834 <p><label for="id_first_name">First name:</label> <input type="text" name="first_name" id="id_first_name" /></p>
    1835 <p><label for="id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></p>
    1836 <p><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /></p>
     1834<p class="required"><label for="id_first_name">First name:</label> <input type="text" name="first_name" id="id_first_name" /></p>
     1835<p class="required"><label for="id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></p>
     1836<p class="required"><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /></p>
    18371837
    18381838Unicode values are handled properly.
    18391839>>> p = Person({'first_name': u'John', 'last_name': u'\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111', 'birthday': '1940-10-9'})
    18401840>>> p.as_table()
    1841 u'<tr><th><label for="id_first_name">First name:</label></th><td><input type="text" name="first_name" value="John" id="id_first_name" /></td></tr>\n<tr><th><label for="id_last_name">Last name:</label></th><td><input type="text" name="last_name" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" id="id_last_name" /></td></tr>\n<tr><th><label for="id_birthday">Birthday:</label></th><td><input type="text" name="birthday" value="1940-10-9" id="id_birthday" /></td></tr>'
     1841u'<tr class="required"><th><label for="id_first_name">First name:</label></th><td><input type="text" name="first_name" value="John" id="id_first_name" /></td></tr>\n<tr class="required"><th><label for="id_last_name">Last name:</label></th><td><input type="text" name="last_name" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" id="id_last_name" /></td></tr>\n<tr class="required"><th><label for="id_birthday">Birthday:</label></th><td><input type="text" name="birthday" value="1940-10-9" id="id_birthday" /></td></tr>'
    18421842>>> p.as_ul()
    1843 u'<li><label for="id_first_name">First name:</label> <input type="text" name="first_name" value="John" id="id_first_name" /></li>\n<li><label for="id_last_name">Last name:</label> <input type="text" name="last_name" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" id="id_last_name" /></li>\n<li><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" value="1940-10-9" id="id_birthday" /></li>'
     1843u'<li class="required"><label for="id_first_name">First name:</label> <input type="text" name="first_name" value="John" id="id_first_name" /></li>\n<li class="required"><label for="id_last_name">Last name:</label> <input type="text" name="last_name" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" id="id_last_name" /></li>\n<li class="required"><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" value="1940-10-9" id="id_birthday" /></li>'
    18441844>>> p.as_p()
    1845 u'<p><label for="id_first_name">First name:</label> <input type="text" name="first_name" value="John" id="id_first_name" /></p>\n<p><label for="id_last_name">Last name:</label> <input type="text" name="last_name" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" id="id_last_name" /></p>\n<p><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" value="1940-10-9" id="id_birthday" /></p>'
     1845u'<p class="required"><label for="id_first_name">First name:</label> <input type="text" name="first_name" value="John" id="id_first_name" /></p>\n<p class="required"><label for="id_last_name">Last name:</label> <input type="text" name="last_name" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" id="id_last_name" /></p>\n<p class="required"><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" value="1940-10-9" id="id_birthday" /></p>'
    18461846
    18471847>>> p = Person({'last_name': u'Lennon'})
    18481848>>> p.errors
     
    18921892the human-readable labels for a field.
    18931893>>> p = Person(auto_id='%s_id')
    18941894>>> print p.as_table()
    1895 <tr><th><label for="first_name_id">First name:</label></th><td><input type="text" name="first_name" id="first_name_id" /></td></tr>
    1896 <tr><th><label for="last_name_id">Last name:</label></th><td><input type="text" name="last_name" id="last_name_id" /></td></tr>
    1897 <tr><th><label for="birthday_id">Birthday:</label></th><td><input type="text" name="birthday" id="birthday_id" /></td></tr>
     1895<tr class="required"><th><label for="first_name_id">First name:</label></th><td><input type="text" name="first_name" id="first_name_id" /></td></tr>
     1896<tr class="required"><th><label for="last_name_id">Last name:</label></th><td><input type="text" name="last_name" id="last_name_id" /></td></tr>
     1897<tr class="required"><th><label for="birthday_id">Birthday:</label></th><td><input type="text" name="birthday" id="birthday_id" /></td></tr>
    18981898>>> print p.as_ul()
    1899 <li><label for="first_name_id">First name:</label> <input type="text" name="first_name" id="first_name_id" /></li>
    1900 <li><label for="last_name_id">Last name:</label> <input type="text" name="last_name" id="last_name_id" /></li>
    1901 <li><label for="birthday_id">Birthday:</label> <input type="text" name="birthday" id="birthday_id" /></li>
     1899<li class="required"><label for="first_name_id">First name:</label> <input type="text" name="first_name" id="first_name_id" /></li>
     1900<li class="required"><label for="last_name_id">Last name:</label> <input type="text" name="last_name" id="last_name_id" /></li>
     1901<li class="required"><label for="birthday_id">Birthday:</label> <input type="text" name="birthday" id="birthday_id" /></li>
    19021902>>> print p.as_p()
    1903 <p><label for="first_name_id">First name:</label> <input type="text" name="first_name" id="first_name_id" /></p>
    1904 <p><label for="last_name_id">Last name:</label> <input type="text" name="last_name" id="last_name_id" /></p>
    1905 <p><label for="birthday_id">Birthday:</label> <input type="text" name="birthday" id="birthday_id" /></p>
     1903<p class="required"><label for="first_name_id">First name:</label> <input type="text" name="first_name" id="first_name_id" /></p>
     1904<p class="required"><label for="last_name_id">Last name:</label> <input type="text" name="last_name" id="last_name_id" /></p>
     1905<p class="required"><label for="birthday_id">Birthday:</label> <input type="text" name="birthday" id="birthday_id" /></p>
    19061906
    19071907If auto_id is any True value whose str() does not contain '%s', the "id"
    19081908attribute will be the name of the field.
    19091909>>> p = Person(auto_id=True)
    19101910>>> print p.as_ul()
    1911 <li><label for="first_name">First name:</label> <input type="text" name="first_name" id="first_name" /></li>
    1912 <li><label for="last_name">Last name:</label> <input type="text" name="last_name" id="last_name" /></li>
    1913 <li><label for="birthday">Birthday:</label> <input type="text" name="birthday" id="birthday" /></li>
     1911<li class="required"><label for="first_name">First name:</label> <input type="text" name="first_name" id="first_name" /></li>
     1912<li class="required"><label for="last_name">Last name:</label> <input type="text" name="last_name" id="last_name" /></li>
     1913<li class="required"><label for="birthday">Birthday:</label> <input type="text" name="birthday" id="birthday" /></li>
    19141914
    19151915If auto_id is any False value, an "id" attribute won't be output unless it
    19161916was manually entered.
    19171917>>> p = Person(auto_id=False)
    19181918>>> print p.as_ul()
    1919 <li>First name: <input type="text" name="first_name" /></li>
    1920 <li>Last name: <input type="text" name="last_name" /></li>
    1921 <li>Birthday: <input type="text" name="birthday" /></li>
     1919<li class="required">First name: <input type="text" name="first_name" /></li>
     1920<li class="required">Last name: <input type="text" name="last_name" /></li>
     1921<li class="required">Birthday: <input type="text" name="birthday" /></li>
    19221922
    19231923In this example, auto_id is False, but the "id" attribute for the "first_name"
    19241924field is given. Also note that field gets a <label>, while the others don't.
     
    19281928...     birthday = DateField()
    19291929>>> p = PersonNew(auto_id=False)
    19301930>>> print p.as_ul()
    1931 <li><label for="first_name_id">First name:</label> <input type="text" id="first_name_id" name="first_name" /></li>
    1932 <li>Last name: <input type="text" name="last_name" /></li>
    1933 <li>Birthday: <input type="text" name="birthday" /></li>
     1931<li class="required"><label for="first_name_id">First name:</label> <input type="text" id="first_name_id" name="first_name" /></li>
     1932<li class="required">Last name: <input type="text" name="last_name" /></li>
     1933<li class="required">Birthday: <input type="text" name="birthday" /></li>
    19341934
    19351935If the "id" attribute is specified in the Form and auto_id is True, the "id"
    19361936attribute in the Form gets precedence.
    19371937>>> p = PersonNew(auto_id=True)
    19381938>>> print p.as_ul()
    1939 <li><label for="first_name_id">First name:</label> <input type="text" id="first_name_id" name="first_name" /></li>
    1940 <li><label for="last_name">Last name:</label> <input type="text" name="last_name" id="last_name" /></li>
    1941 <li><label for="birthday">Birthday:</label> <input type="text" name="birthday" id="birthday" /></li>
     1939<li class="required"><label for="first_name_id">First name:</label> <input type="text" id="first_name_id" name="first_name" /></li>
     1940<li class="required"><label for="last_name">Last name:</label> <input type="text" name="last_name" id="last_name" /></li>
     1941<li class="required"><label for="birthday">Birthday:</label> <input type="text" name="birthday" id="birthday" /></li>
    19421942
    19431943>>> class SignupForm(Form):
    19441944...     email = EmailField()
     
    20862086<li><label><input type="radio" name="language" value="J" /> Java</label></li>
    20872087</ul>
    20882088>>> print f
    2089 <tr><th>Name:</th><td><input type="text" name="name" /></td></tr>
    2090 <tr><th>Language:</th><td><ul>
     2089<tr class="required"><th>Name:</th><td><input type="text" name="name" /></td></tr>
     2090<tr class="required"><th>Language:</th><td><ul>
    20912091<li><label><input type="radio" name="language" value="P" /> Python</label></li>
    20922092<li><label><input type="radio" name="language" value="J" /> Java</label></li>
    20932093</ul></td></tr>
    20942094>>> print f.as_ul()
    2095 <li>Name: <input type="text" name="name" /></li>
    2096 <li>Language: <ul>
     2095<li class="required">Name: <input type="text" name="name" /></li>
     2096<li class="required">Language: <ul>
    20972097<li><label><input type="radio" name="language" value="P" /> Python</label></li>
    20982098<li><label><input type="radio" name="language" value="J" /> Java</label></li>
    20992099</ul></li>
     
    21122112either as_table() or as_ul(), the label for the RadioSelect will point to the
    21132113ID of the *first* radio button.
    21142114>>> print f
    2115 <tr><th><label for="id_name">Name:</label></th><td><input type="text" name="name" id="id_name" /></td></tr>
    2116 <tr><th><label for="id_language_0">Language:</label></th><td><ul>
     2115<tr class="required"><th><label for="id_name">Name:</label></th><td><input type="text" name="name" id="id_name" /></td></tr>
     2116<tr class="required"><th><label for="id_language_0">Language:</label></th><td><ul>
    21172117<li><label><input type="radio" id="id_language_0" value="P" name="language" /> Python</label></li>
    21182118<li><label><input type="radio" id="id_language_1" value="J" name="language" /> Java</label></li>
    21192119</ul></td></tr>
    21202120>>> print f.as_ul()
    2121 <li><label for="id_name">Name:</label> <input type="text" name="name" id="id_name" /></li>
    2122 <li><label for="id_language_0">Language:</label> <ul>
     2121<li class="required"><label for="id_name">Name:</label> <input type="text" name="name" id="id_name" /></li>
     2122<li class="required"><label for="id_language_0">Language:</label> <ul>
    21232123<li><label><input type="radio" id="id_language_0" value="P" name="language" /> Python</label></li>
    21242124<li><label><input type="radio" id="id_language_1" value="J" name="language" /> Java</label></li>
    21252125</ul></li>
    21262126>>> print f.as_p()
    2127 <p><label for="id_name">Name:</label> <input type="text" name="name" id="id_name" /></p>
    2128 <p><label for="id_language_0">Language:</label> <ul>
     2127<p class="required"><label for="id_name">Name:</label> <input type="text" name="name" id="id_name" /></p>
     2128<p class="required"><label for="id_language_0">Language:</label> <ul>
    21292129<li><label><input type="radio" id="id_language_0" value="P" name="language" /> Python</label></li>
    21302130<li><label><input type="radio" id="id_language_1" value="J" name="language" /> Java</label></li>
    21312131</ul></p>
     
    22232223...     composers = MultipleChoiceField(choices=[('J', 'John Lennon'), ('P', 'Paul McCartney')], widget=MultipleHiddenInput)
    22242224>>> f = SongFormHidden(MultiValueDict(dict(name=['Yesterday'], composers=['J', 'P'])), auto_id=False)
    22252225>>> print f.as_ul()
    2226 <li>Name: <input type="text" name="name" value="Yesterday" /><input type="hidden" name="composers" value="J" />
     2226<li class="required">Name: <input type="text" name="name" value="Yesterday" /><input type="hidden" name="composers" value="J" />
    22272227<input type="hidden" name="composers" value="P" /></li>
    22282228
    22292229When using CheckboxSelectMultiple, the framework expects a list of input and
     
    22502250
    22512251>>> f = EscapingForm({'special_name': "Nothing to escape"}, auto_id=False)
    22522252>>> print f
    2253 <tr><th>Special name:</th><td><ul class="errorlist"><li>Something&#39;s wrong with &#39;Nothing to escape&#39;</li></ul><input type="text" name="special_name" value="Nothing to escape" /></td></tr>
     2253<tr class="error required"><th>Special name:</th><td><ul class="errorlist"><li>Something&#39;s wrong with &#39;Nothing to escape&#39;</li></ul><input type="text" name="special_name" value="Nothing to escape" /></td></tr>
    22542254>>> f = EscapingForm({'special_name': "Should escape < & > and <script>alert('xss')</script>"}, auto_id=False)
    22552255>>> print f
    2256 <tr><th>Special name:</th><td><ul class="errorlist"><li>Something&#39;s wrong with &#39;Should escape &lt; &amp; &gt; and &lt;script&gt;alert(&#39;xss&#39;)&lt;/script&gt;&#39;</li></ul><input type="text" name="special_name" value="Should escape &lt; &amp; &gt; and &lt;script&gt;alert(&#39;xss&#39;)&lt;/script&gt;" /></td></tr>
     2256<tr class="error required"><th>Special name:</th><td><ul class="errorlist"><li>Something&#39;s wrong with &#39;Should escape &lt; &amp; &gt; and &lt;script&gt;alert(&#39;xss&#39;)&lt;/script&gt;&#39;</li></ul><input type="text" name="special_name" value="Should escape &lt; &amp; &gt; and &lt;script&gt;alert(&#39;xss&#39;)&lt;/script&gt;" /></td></tr>
    22572257
    22582258# Validating multiple fields in relation to another ###########################
    22592259
     
    23072307{}
    23082308>>> f = UserRegistration({}, auto_id=False)
    23092309>>> print f.as_table()
    2310 <tr><th>Username:</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="username" maxlength="10" /></td></tr>
    2311 <tr><th>Password1:</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="password" name="password1" /></td></tr>
    2312 <tr><th>Password2:</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="password" name="password2" /></td></tr>
     2310<tr class="error required"><th>Username:</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="username" maxlength="10" /></td></tr>
     2311<tr class="error required"><th>Password1:</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="password" name="password1" /></td></tr>
     2312<tr class="error required"><th>Password2:</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="password" name="password2" /></td></tr>
    23132313>>> f.errors
    23142314{'username': [u'This field is required.'], 'password1': [u'This field is required.'], 'password2': [u'This field is required.']}
    23152315>>> f = UserRegistration({'username': 'adrian', 'password1': 'foo', 'password2': 'bar'}, auto_id=False)
     
    23172317{'__all__': [u'Please make sure your passwords match.']}
    23182318>>> print f.as_table()
    23192319<tr><td colspan="2"><ul class="errorlist"><li>Please make sure your passwords match.</li></ul></td></tr>
    2320 <tr><th>Username:</th><td><input type="text" name="username" value="adrian" maxlength="10" /></td></tr>
    2321 <tr><th>Password1:</th><td><input type="password" name="password1" value="foo" /></td></tr>
    2322 <tr><th>Password2:</th><td><input type="password" name="password2" value="bar" /></td></tr>
     2320<tr class="required"><th>Username:</th><td><input type="text" name="username" value="adrian" maxlength="10" /></td></tr>
     2321<tr class="required"><th>Password1:</th><td><input type="password" name="password1" value="foo" /></td></tr>
     2322<tr class="required"><th>Password2:</th><td><input type="password" name="password2" value="bar" /></td></tr>
    23232323>>> print f.as_ul()
    23242324<li><ul class="errorlist"><li>Please make sure your passwords match.</li></ul></li>
    2325 <li>Username: <input type="text" name="username" value="adrian" maxlength="10" /></li>
    2326 <li>Password1: <input type="password" name="password1" value="foo" /></li>
    2327 <li>Password2: <input type="password" name="password2" value="bar" /></li>
     2325<li class="required">Username: <input type="text" name="username" value="adrian" maxlength="10" /></li>
     2326<li class="required">Password1: <input type="password" name="password1" value="foo" /></li>
     2327<li class="required">Password2: <input type="password" name="password2" value="bar" /></li>
    23282328>>> f = UserRegistration({'username': 'adrian', 'password1': 'foo', 'password2': 'foo'}, auto_id=False)
    23292329>>> f.errors
    23302330{}
     
    23442344...         self.fields['birthday'] = DateField()
    23452345>>> p = Person(auto_id=False)
    23462346>>> print p
    2347 <tr><th>First name:</th><td><input type="text" name="first_name" /></td></tr>
    2348 <tr><th>Last name:</th><td><input type="text" name="last_name" /></td></tr>
    2349 <tr><th>Birthday:</th><td><input type="text" name="birthday" /></td></tr>
     2347<tr class="required"><th>First name:</th><td><input type="text" name="first_name" /></td></tr>
     2348<tr class="required"><th>Last name:</th><td><input type="text" name="last_name" /></td></tr>
     2349<tr class="required"><th>Birthday:</th><td><input type="text" name="birthday" /></td></tr>
    23502350
    23512351Instances of a dynamic Form do not persist fields from one Form instance to
    23522352the next.
     
    23582358>>> field_list = [('field1', CharField()), ('field2', CharField())]
    23592359>>> my_form = MyForm(field_list=field_list)
    23602360>>> print my_form
    2361 <tr><th>Field1:</th><td><input type="text" name="field1" /></td></tr>
    2362 <tr><th>Field2:</th><td><input type="text" name="field2" /></td></tr>
     2361<tr class="required"><th>Field1:</th><td><input type="text" name="field1" /></td></tr>
     2362<tr class="required"><th>Field2:</th><td><input type="text" name="field2" /></td></tr>
    23632363>>> field_list = [('field3', CharField()), ('field4', CharField())]
    23642364>>> my_form = MyForm(field_list=field_list)
    23652365>>> print my_form
    2366 <tr><th>Field3:</th><td><input type="text" name="field3" /></td></tr>
    2367 <tr><th>Field4:</th><td><input type="text" name="field4" /></td></tr>
     2366<tr class="required"><th>Field3:</th><td><input type="text" name="field3" /></td></tr>
     2367<tr class="required"><th>Field4:</th><td><input type="text" name="field4" /></td></tr>
    23682368
    23692369>>> class MyForm(Form):
    23702370...     default_field_1 = CharField()
     
    23762376>>> field_list = [('field1', CharField()), ('field2', CharField())]
    23772377>>> my_form = MyForm(field_list=field_list)
    23782378>>> print my_form
    2379 <tr><th>Default field 1:</th><td><input type="text" name="default_field_1" /></td></tr>
    2380 <tr><th>Default field 2:</th><td><input type="text" name="default_field_2" /></td></tr>
    2381 <tr><th>Field1:</th><td><input type="text" name="field1" /></td></tr>
    2382 <tr><th>Field2:</th><td><input type="text" name="field2" /></td></tr>
     2379<tr class="required"><th>Default field 1:</th><td><input type="text" name="default_field_1" /></td></tr>
     2380<tr class="required"><th>Default field 2:</th><td><input type="text" name="default_field_2" /></td></tr>
     2381<tr class="required"><th>Field1:</th><td><input type="text" name="field1" /></td></tr>
     2382<tr class="required"><th>Field2:</th><td><input type="text" name="field2" /></td></tr>
    23832383>>> field_list = [('field3', CharField()), ('field4', CharField())]
    23842384>>> my_form = MyForm(field_list=field_list)
    23852385>>> print my_form
    2386 <tr><th>Default field 1:</th><td><input type="text" name="default_field_1" /></td></tr>
    2387 <tr><th>Default field 2:</th><td><input type="text" name="default_field_2" /></td></tr>
    2388 <tr><th>Field3:</th><td><input type="text" name="field3" /></td></tr>
    2389 <tr><th>Field4:</th><td><input type="text" name="field4" /></td></tr>
     2386<tr class="required"><th>Default field 1:</th><td><input type="text" name="default_field_1" /></td></tr>
     2387<tr class="required"><th>Default field 2:</th><td><input type="text" name="default_field_2" /></td></tr>
     2388<tr class="required"><th>Field3:</th><td><input type="text" name="field3" /></td></tr>
     2389<tr class="required"><th>Field4:</th><td><input type="text" name="field4" /></td></tr>
    23902390
    23912391Similarly, changes to field attributes do not persist from one Form instance
    23922392to the next.
     
    24362436...     birthday = DateField()
    24372437>>> p = Person(auto_id=False)
    24382438>>> print p
    2439 <tr><th>First name:</th><td><input type="text" name="first_name" /></td></tr>
    2440 <tr><th>Last name:</th><td><input type="text" name="last_name" /></td></tr>
    2441 <tr><th>Birthday:</th><td><input type="text" name="birthday" /><input type="hidden" name="hidden_text" /></td></tr>
     2439<tr class="required"><th>First name:</th><td><input type="text" name="first_name" /></td></tr>
     2440<tr class="required"><th>Last name:</th><td><input type="text" name="last_name" /></td></tr>
     2441<tr class="required"><th>Birthday:</th><td><input type="text" name="birthday" /><input type="hidden" name="hidden_text" /></td></tr>
    24422442>>> print p.as_ul()
    2443 <li>First name: <input type="text" name="first_name" /></li>
    2444 <li>Last name: <input type="text" name="last_name" /></li>
    2445 <li>Birthday: <input type="text" name="birthday" /><input type="hidden" name="hidden_text" /></li>
     2443<li class="required">First name: <input type="text" name="first_name" /></li>
     2444<li class="required">Last name: <input type="text" name="last_name" /></li>
     2445<li class="required">Birthday: <input type="text" name="birthday" /><input type="hidden" name="hidden_text" /></li>
    24462446>>> print p.as_p()
    2447 <p>First name: <input type="text" name="first_name" /></p>
    2448 <p>Last name: <input type="text" name="last_name" /></p>
    2449 <p>Birthday: <input type="text" name="birthday" /><input type="hidden" name="hidden_text" /></p>
     2447<p class="required">First name: <input type="text" name="first_name" /></p>
     2448<p class="required">Last name: <input type="text" name="last_name" /></p>
     2449<p class="required">Birthday: <input type="text" name="birthday" /><input type="hidden" name="hidden_text" /></p>
    24502450
    24512451With auto_id set, a HiddenInput still gets an ID, but it doesn't get a label.
    24522452>>> p = Person(auto_id='id_%s')
    24532453>>> print p
    2454 <tr><th><label for="id_first_name">First name:</label></th><td><input type="text" name="first_name" id="id_first_name" /></td></tr>
    2455 <tr><th><label for="id_last_name">Last name:</label></th><td><input type="text" name="last_name" id="id_last_name" /></td></tr>
    2456 <tr><th><label for="id_birthday">Birthday:</label></th><td><input type="text" name="birthday" id="id_birthday" /><input type="hidden" name="hidden_text" id="id_hidden_text" /></td></tr>
     2454<tr class="required"><th><label for="id_first_name">First name:</label></th><td><input type="text" name="first_name" id="id_first_name" /></td></tr>
     2455<tr class="required"><th><label for="id_last_name">Last name:</label></th><td><input type="text" name="last_name" id="id_last_name" /></td></tr>
     2456<tr class="required"><th><label for="id_birthday">Birthday:</label></th><td><input type="text" name="birthday" id="id_birthday" /><input type="hidden" name="hidden_text" id="id_hidden_text" /></td></tr>
    24572457>>> print p.as_ul()
    2458 <li><label for="id_first_name">First name:</label> <input type="text" name="first_name" id="id_first_name" /></li>
    2459 <li><label for="id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></li>
    2460 <li><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /><input type="hidden" name="hidden_text" id="id_hidden_text" /></li>
     2458<li class="required"><label for="id_first_name">First name:</label> <input type="text" name="first_name" id="id_first_name" /></li>
     2459<li class="required"><label for="id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></li>
     2460<li class="required"><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /><input type="hidden" name="hidden_text" id="id_hidden_text" /></li>
    24612461>>> print p.as_p()
    2462 <p><label for="id_first_name">First name:</label> <input type="text" name="first_name" id="id_first_name" /></p>
    2463 <p><label for="id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></p>
    2464 <p><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /><input type="hidden" name="hidden_text" id="id_hidden_text" /></p>
     2462<p class="required"><label for="id_first_name">First name:</label> <input type="text" name="first_name" id="id_first_name" /></p>
     2463<p class="required"><label for="id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></p>
     2464<p class="required"><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /><input type="hidden" name="hidden_text" id="id_hidden_text" /></p>
    24652465
    24662466If a field with a HiddenInput has errors, the as_table() and as_ul() output
    24672467will include the error message(s) with the text "(Hidden field [fieldname]) "
     
    24702470>>> p = Person({'first_name': 'John', 'last_name': 'Lennon', 'birthday': '1940-10-9'}, auto_id=False)
    24712471>>> print p
    24722472<tr><td colspan="2"><ul class="errorlist"><li>(Hidden field hidden_text) This field is required.</li></ul></td></tr>
    2473 <tr><th>First name:</th><td><input type="text" name="first_name" value="John" /></td></tr>
    2474 <tr><th>Last name:</th><td><input type="text" name="last_name" value="Lennon" /></td></tr>
    2475 <tr><th>Birthday:</th><td><input type="text" name="birthday" value="1940-10-9" /><input type="hidden" name="hidden_text" /></td></tr>
     2473<tr class="required"><th>First name:</th><td><input type="text" name="first_name" value="John" /></td></tr>
     2474<tr class="required"><th>Last name:</th><td><input type="text" name="last_name" value="Lennon" /></td></tr>
     2475<tr class="required"><th>Birthday:</th><td><input type="text" name="birthday" value="1940-10-9" /><input type="hidden" name="hidden_text" /></td></tr>
    24762476>>> print p.as_ul()
    24772477<li><ul class="errorlist"><li>(Hidden field hidden_text) This field is required.</li></ul></li>
    2478 <li>First name: <input type="text" name="first_name" value="John" /></li>
    2479 <li>Last name: <input type="text" name="last_name" value="Lennon" /></li>
    2480 <li>Birthday: <input type="text" name="birthday" value="1940-10-9" /><input type="hidden" name="hidden_text" /></li>
     2478<li class="required">First name: <input type="text" name="first_name" value="John" /></li>
     2479<li class="required">Last name: <input type="text" name="last_name" value="Lennon" /></li>
     2480<li class="required">Birthday: <input type="text" name="birthday" value="1940-10-9" /><input type="hidden" name="hidden_text" /></li>
    24812481>>> print p.as_p()
    24822482<p><ul class="errorlist"><li>(Hidden field hidden_text) This field is required.</li></ul></p>
    2483 <p>First name: <input type="text" name="first_name" value="John" /></p>
    2484 <p>Last name: <input type="text" name="last_name" value="Lennon" /></p>
    2485 <p>Birthday: <input type="text" name="birthday" value="1940-10-9" /><input type="hidden" name="hidden_text" /></p>
     2483<p class="required">First name: <input type="text" name="first_name" value="John" /></p>
     2484<p class="required">Last name: <input type="text" name="last_name" value="Lennon" /></p>
     2485<p class="required">Birthday: <input type="text" name="birthday" value="1940-10-9" /><input type="hidden" name="hidden_text" /></p>
    24862486
    24872487A corner case: It's possible for a form to have only HiddenInputs.
    24882488>>> class TestForm(Form):
     
    25142514...     field14 = CharField()
    25152515>>> p = TestForm(auto_id=False)
    25162516>>> print p
    2517 <tr><th>Field1:</th><td><input type="text" name="field1" /></td></tr>
    2518 <tr><th>Field2:</th><td><input type="text" name="field2" /></td></tr>
    2519 <tr><th>Field3:</th><td><input type="text" name="field3" /></td></tr>
    2520 <tr><th>Field4:</th><td><input type="text" name="field4" /></td></tr>
    2521 <tr><th>Field5:</th><td><input type="text" name="field5" /></td></tr>
    2522 <tr><th>Field6:</th><td><input type="text" name="field6" /></td></tr>
    2523 <tr><th>Field7:</th><td><input type="text" name="field7" /></td></tr>
    2524 <tr><th>Field8:</th><td><input type="text" name="field8" /></td></tr>
    2525 <tr><th>Field9:</th><td><input type="text" name="field9" /></td></tr>
    2526 <tr><th>Field10:</th><td><input type="text" name="field10" /></td></tr>
    2527 <tr><th>Field11:</th><td><input type="text" name="field11" /></td></tr>
    2528 <tr><th>Field12:</th><td><input type="text" name="field12" /></td></tr>
    2529 <tr><th>Field13:</th><td><input type="text" name="field13" /></td></tr>
    2530 <tr><th>Field14:</th><td><input type="text" name="field14" /></td></tr>
     2517<tr class="required"><th>Field1:</th><td><input type="text" name="field1" /></td></tr>
     2518<tr class="required"><th>Field2:</th><td><input type="text" name="field2" /></td></tr>
     2519<tr class="required"><th>Field3:</th><td><input type="text" name="field3" /></td></tr>
     2520<tr class="required"><th>Field4:</th><td><input type="text" name="field4" /></td></tr>
     2521<tr class="required"><th>Field5:</th><td><input type="text" name="field5" /></td></tr>
     2522<tr class="required"><th>Field6:</th><td><input type="text" name="field6" /></td></tr>
     2523<tr class="required"><th>Field7:</th><td><input type="text" name="field7" /></td></tr>
     2524<tr class="required"><th>Field8:</th><td><input type="text" name="field8" /></td></tr>
     2525<tr class="required"><th>Field9:</th><td><input type="text" name="field9" /></td></tr>
     2526<tr class="required"><th>Field10:</th><td><input type="text" name="field10" /></td></tr>
     2527<tr class="required"><th>Field11:</th><td><input type="text" name="field11" /></td></tr>
     2528<tr class="required"><th>Field12:</th><td><input type="text" name="field12" /></td></tr>
     2529<tr class="required"><th>Field13:</th><td><input type="text" name="field13" /></td></tr>
     2530<tr class="required"><th>Field14:</th><td><input type="text" name="field14" /></td></tr>
    25312531
    25322532Some Field classes have an effect on the HTML attributes of their associated
    25332533Widget. If you set max_length in a CharField and its associated widget is
     
    25402540...    address = CharField()                                 # no max_length defined here
    25412541>>> p = UserRegistration(auto_id=False)
    25422542>>> print p.as_ul()
    2543 <li>Username: <input type="text" name="username" maxlength="10" /></li>
    2544 <li>Password: <input type="password" name="password" maxlength="10" /></li>
    2545 <li>Realname: <input type="text" name="realname" maxlength="10" /></li>
    2546 <li>Address: <input type="text" name="address" /></li>
     2543<li class="required">Username: <input type="text" name="username" maxlength="10" /></li>
     2544<li class="required">Password: <input type="password" name="password" maxlength="10" /></li>
     2545<li class="required">Realname: <input type="text" name="realname" maxlength="10" /></li>
     2546<li class="required">Address: <input type="text" name="address" /></li>
    25472547
    25482548If you specify a custom "attrs" that includes the "maxlength" attribute,
    25492549the Field's max_length attribute will override whatever "maxlength" you specify
     
    25532553...    password = CharField(max_length=10, widget=PasswordInput)
    25542554>>> p = UserRegistration(auto_id=False)
    25552555>>> print p.as_ul()
    2556 <li>Username: <input type="text" name="username" maxlength="10" /></li>
    2557 <li>Password: <input type="password" name="password" maxlength="10" /></li>
     2556<li class="required">Username: <input type="text" name="username" maxlength="10" /></li>
     2557<li class="required">Password: <input type="password" name="password" maxlength="10" /></li>
    25582558
    25592559# Specifying labels ###########################################################
    25602560
     
    25672567...    password2 = CharField(widget=PasswordInput, label='Password (again)')
    25682568>>> p = UserRegistration(auto_id=False)
    25692569>>> print p.as_ul()
    2570 <li>Your username: <input type="text" name="username" maxlength="10" /></li>
    2571 <li>Password1: <input type="password" name="password1" /></li>
    2572 <li>Password (again): <input type="password" name="password2" /></li>
     2570<li class="required">Your username: <input type="text" name="username" maxlength="10" /></li>
     2571<li class="required">Password1: <input type="password" name="password1" /></li>
     2572<li class="required">Password (again): <input type="password" name="password2" /></li>
    25732573
    25742574A label can be a Unicode object or a bytestring with special characters.
    25752575>>> class UserRegistration(Form):
     
    25772577...    password = CharField(widget=PasswordInput, label=u'\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111')
    25782578>>> p = UserRegistration(auto_id=False)
    25792579>>> p.as_ul()
    2580 u'<li>\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111: <input type="text" name="username" maxlength="10" /></li>\n<li>\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111: <input type="password" name="password" /></li>'
     2580u'<li class="required">\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111: <input type="text" name="username" maxlength="10" /></li>\n<li class="required">\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111: <input type="password" name="password" /></li>'
    25812581
    25822582If a label is set to the empty string for a field, that field won't get a label.
    25832583>>> class UserRegistration(Form):
     
    25852585...    password = CharField(widget=PasswordInput)
    25862586>>> p = UserRegistration(auto_id=False)
    25872587>>> print p.as_ul()
    2588 <li> <input type="text" name="username" maxlength="10" /></li>
    2589 <li>Password: <input type="password" name="password" /></li>
     2588<li class="required"> <input type="text" name="username" maxlength="10" /></li>
     2589<li class="required">Password: <input type="password" name="password" /></li>
    25902590>>> p = UserRegistration(auto_id='id_%s')
    25912591>>> print p.as_ul()
    2592 <li> <input id="id_username" type="text" name="username" maxlength="10" /></li>
    2593 <li><label for="id_password">Password:</label> <input type="password" name="password" id="id_password" /></li>
     2592<li class="required"> <input id="id_username" type="text" name="username" maxlength="10" /></li>
     2593<li class="required"><label for="id_password">Password:</label> <input type="password" name="password" id="id_password" /></li>
    25942594
    25952595If label is None, Django will auto-create the label from the field name. This
    25962596is default behavior.
     
    25992599...    password = CharField(widget=PasswordInput)
    26002600>>> p = UserRegistration(auto_id=False)
    26012601>>> print p.as_ul()
    2602 <li>Username: <input type="text" name="username" maxlength="10" /></li>
    2603 <li>Password: <input type="password" name="password" /></li>
     2602<li class="required">Username: <input type="text" name="username" maxlength="10" /></li>
     2603<li class="required">Password: <input type="password" name="password" /></li>
    26042604>>> p = UserRegistration(auto_id='id_%s')
    26052605>>> print p.as_ul()
    2606 <li><label for="id_username">Username:</label> <input id="id_username" type="text" name="username" maxlength="10" /></li>
    2607 <li><label for="id_password">Password:</label> <input type="password" name="password" id="id_password" /></li>
     2606<li class="required"><label for="id_username">Username:</label> <input id="id_username" type="text" name="username" maxlength="10" /></li>
     2607<li class="required"><label for="id_password">Password:</label> <input type="password" name="password" id="id_password" /></li>
    26082608
    26092609# Initial data ################################################################
    26102610
     
    26202620Here, we're not submitting any data, so the initial value will be displayed.
    26212621>>> p = UserRegistration(auto_id=False)
    26222622>>> print p.as_ul()
    2623 <li>Username: <input type="text" name="username" value="django" maxlength="10" /></li>
    2624 <li>Password: <input type="password" name="password" /></li>
     2623<li class="required">Username: <input type="text" name="username" value="django" maxlength="10" /></li>
     2624<li class="required">Password: <input type="password" name="password" /></li>
    26252625
    26262626Here, we're submitting data, so the initial value will *not* be displayed.
    26272627>>> p = UserRegistration({}, auto_id=False)
    26282628>>> print p.as_ul()
    2629 <li><ul class="errorlist"><li>This field is required.</li></ul>Username: <input type="text" name="username" maxlength="10" /></li>
    2630 <li><ul class="errorlist"><li>This field is required.</li></ul>Password: <input type="password" name="password" /></li>
     2629<li class="error required"><ul class="errorlist"><li>This field is required.</li></ul>Username: <input type="text" name="username" maxlength="10" /></li>
     2630<li class="error required"><ul class="errorlist"><li>This field is required.</li></ul>Password: <input type="password" name="password" /></li>
    26312631>>> p = UserRegistration({'username': u''}, auto_id=False)
    26322632>>> print p.as_ul()
    2633 <li><ul class="errorlist"><li>This field is required.</li></ul>Username: <input type="text" name="username" maxlength="10" /></li>
    2634 <li><ul class="errorlist"><li>This field is required.</li></ul>Password: <input type="password" name="password" /></li>
     2633<li class="error required"><ul class="errorlist"><li>This field is required.</li></ul>Username: <input type="text" name="username" maxlength="10" /></li>
     2634<li class="error required"><ul class="errorlist"><li>This field is required.</li></ul>Password: <input type="password" name="password" /></li>
    26352635>>> p = UserRegistration({'username': u'foo'}, auto_id=False)
    26362636>>> print p.as_ul()
    2637 <li>Username: <input type="text" name="username" value="foo" maxlength="10" /></li>
    2638 <li><ul class="errorlist"><li>This field is required.</li></ul>Password: <input type="password" name="password" /></li>
     2637<li class="required">Username: <input type="text" name="username" value="foo" maxlength="10" /></li>
     2638<li class="error required"><ul class="errorlist"><li>This field is required.</li></ul>Password: <input type="password" name="password" /></li>
    26392639
    26402640An 'initial' value is *not* used as a fallback if data is not provided. In this
    26412641example, we don't provide a value for 'username', and the form raises a
     
    26612661Here, we're not submitting any data, so the initial value will be displayed.
    26622662>>> p = UserRegistration(initial={'username': 'django'}, auto_id=False)
    26632663>>> print p.as_ul()
    2664 <li>Username: <input type="text" name="username" value="django" maxlength="10" /></li>
    2665 <li>Password: <input type="password" name="password" /></li>
     2664<li class="required">Username: <input type="text" name="username" value="django" maxlength="10" /></li>
     2665<li class="required">Password: <input type="password" name="password" /></li>
    26662666>>> p = UserRegistration(initial={'username': 'stephane'}, auto_id=False)
    26672667>>> print p.as_ul()
    2668 <li>Username: <input type="text" name="username" value="stephane" maxlength="10" /></li>
    2669 <li>Password: <input type="password" name="password" /></li>
     2668<li class="required">Username: <input type="text" name="username" value="stephane" maxlength="10" /></li>
     2669<li class="required">Password: <input type="password" name="password" /></li>
    26702670
    26712671The 'initial' parameter is meaningless if you pass data.
    26722672>>> p = UserRegistration({}, initial={'username': 'django'}, auto_id=False)
    26732673>>> print p.as_ul()
    2674 <li><ul class="errorlist"><li>This field is required.</li></ul>Username: <input type="text" name="username" maxlength="10" /></li>
    2675 <li><ul class="errorlist"><li>This field is required.</li></ul>Password: <input type="password" name="password" /></li>
     2674<li class="error required"><ul class="errorlist"><li>This field is required.</li></ul>Username: <input type="text" name="username" maxlength="10" /></li>
     2675<li class="error required"><ul class="errorlist"><li>This field is required.</li></ul>Password: <input type="password" name="password" /></li>
    26762676>>> p = UserRegistration({'username': u''}, initial={'username': 'django'}, auto_id=False)
    26772677>>> print p.as_ul()
    2678 <li><ul class="errorlist"><li>This field is required.</li></ul>Username: <input type="text" name="username" maxlength="10" /></li>
    2679 <li><ul class="errorlist"><li>This field is required.</li></ul>Password: <input type="password" name="password" /></li>
     2678<li class="error required"><ul class="errorlist"><li>This field is required.</li></ul>Username: <input type="text" name="username" maxlength="10" /></li>
     2679<li class="error required"><ul class="errorlist"><li>This field is required.</li></ul>Password: <input type="password" name="password" /></li>
    26802680>>> p = UserRegistration({'username': u'foo'}, initial={'username': 'django'}, auto_id=False)
    26812681>>> print p.as_ul()
    2682 <li>Username: <input type="text" name="username" value="foo" maxlength="10" /></li>
    2683 <li><ul class="errorlist"><li>This field is required.</li></ul>Password: <input type="password" name="password" /></li>
     2682<li class="required">Username: <input type="text" name="username" value="foo" maxlength="10" /></li>
     2683<li class="error required"><ul class="errorlist"><li>This field is required.</li></ul>Password: <input type="password" name="password" /></li>
    26842684
    26852685A dynamic 'initial' value is *not* used as a fallback if data is not provided.
    26862686In this example, we don't provide a value for 'username', and the form raises a
     
    26982698...    password = CharField(widget=PasswordInput)
    26992699>>> p = UserRegistration(initial={'username': 'babik'}, auto_id=False)
    27002700>>> print p.as_ul()
    2701 <li>Username: <input type="text" name="username" value="babik" maxlength="10" /></li>
    2702 <li>Password: <input type="password" name="password" /></li>
     2701<li class="required">Username: <input type="text" name="username" value="babik" maxlength="10" /></li>
     2702<li class="required">Password: <input type="password" name="password" /></li>
    27032703
    27042704# Help text ###################################################################
    27052705
     
    27102710...    password = CharField(widget=PasswordInput, help_text='Choose wisely.')
    27112711>>> p = UserRegistration(auto_id=False)
    27122712>>> print p.as_ul()
    2713 <li>Username: <input type="text" name="username" maxlength="10" /> e.g., user@example.com</li>
    2714 <li>Password: <input type="password" name="password" /> Choose wisely.</li>
     2713<li class="required">Username: <input type="text" name="username" maxlength="10" /> e.g., user@example.com</li>
     2714<li class="required">Password: <input type="password" name="password" /> Choose wisely.</li>
    27152715>>> print p.as_p()
    2716 <p>Username: <input type="text" name="username" maxlength="10" /> e.g., user@example.com</p>
    2717 <p>Password: <input type="password" name="password" /> Choose wisely.</p>
     2716<p class="required">Username: <input type="text" name="username" maxlength="10" /> e.g., user@example.com</p>
     2717<p class="required">Password: <input type="password" name="password" /> Choose wisely.</p>
    27182718>>> print p.as_table()
    2719 <tr><th>Username:</th><td><input type="text" name="username" maxlength="10" /><br />e.g., user@example.com</td></tr>
    2720 <tr><th>Password:</th><td><input type="password" name="password" /><br />Choose wisely.</td></tr>
     2719<tr class="required"><th>Username:</th><td><input type="text" name="username" maxlength="10" /><br />e.g., user@example.com</td></tr>
     2720<tr class="required"><th>Password:</th><td><input type="password" name="password" /><br />Choose wisely.</td></tr>
    27212721
    27222722The help text is displayed whether or not data is provided for the form.
    27232723>>> p = UserRegistration({'username': u'foo'}, auto_id=False)
    27242724>>> print p.as_ul()
    2725 <li>Username: <input type="text" name="username" value="foo" maxlength="10" /> e.g., user@example.com</li>
    2726 <li><ul class="errorlist"><li>This field is required.</li></ul>Password: <input type="password" name="password" /> Choose wisely.</li>
     2725<li class="required">Username: <input type="text" name="username" value="foo" maxlength="10" /> e.g., user@example.com</li>
     2726<li class="error required"><ul class="errorlist"><li>This field is required.</li></ul>Password: <input type="password" name="password" /> Choose wisely.</li>
    27272727
    27282728help_text is not displayed for hidden fields. It can be used for documentation
    27292729purposes, though.
     
    27332733...    next = CharField(widget=HiddenInput, initial='/', help_text='Redirect destination')
    27342734>>> p = UserRegistration(auto_id=False)
    27352735>>> print p.as_ul()
    2736 <li>Username: <input type="text" name="username" maxlength="10" /> e.g., user@example.com</li>
    2737 <li>Password: <input type="password" name="password" /><input type="hidden" name="next" value="/" /></li>
     2736<li class="required">Username: <input type="text" name="username" maxlength="10" /> e.g., user@example.com</li>
     2737<li class="required">Password: <input type="password" name="password" /><input type="hidden" name="next" value="/" /></li>
    27382738
    27392739Help text can include arbitrary Unicode characters.
    27402740>>> class UserRegistration(Form):
    27412741...    username = CharField(max_length=10, help_text='ŠĐĆŽćžšđ')
    27422742>>> p = UserRegistration(auto_id=False)
    27432743>>> p.as_ul()
    2744 u'<li>Username: <input type="text" name="username" maxlength="10" /> \u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111</li>'
     2744u'<li class="required">Username: <input type="text" name="username" maxlength="10" /> \u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111</li>'
    27452745
    27462746# Subclassing forms ###########################################################
    27472747
     
    27562756...     instrument = CharField()
    27572757>>> p = Person(auto_id=False)
    27582758>>> print p.as_ul()
    2759 <li>First name: <input type="text" name="first_name" /></li>
    2760 <li>Last name: <input type="text" name="last_name" /></li>
    2761 <li>Birthday: <input type="text" name="birthday" /></li>
     2759<li class="required">First name: <input type="text" name="first_name" /></li>
     2760<li class="required">Last name: <input type="text" name="last_name" /></li>
     2761<li class="required">Birthday: <input type="text" name="birthday" /></li>
    27622762>>> m = Musician(auto_id=False)
    27632763>>> print m.as_ul()
    2764 <li>First name: <input type="text" name="first_name" /></li>
    2765 <li>Last name: <input type="text" name="last_name" /></li>
    2766 <li>Birthday: <input type="text" name="birthday" /></li>
    2767 <li>Instrument: <input type="text" name="instrument" /></li>
     2764<li class="required">First name: <input type="text" name="first_name" /></li>
     2765<li class="required">Last name: <input type="text" name="last_name" /></li>
     2766<li class="required">Birthday: <input type="text" name="birthday" /></li>
     2767<li class="required">Instrument: <input type="text" name="instrument" /></li>
    27682768
    27692769Yes, you can subclass multiple forms. The fields are added in the order in
    27702770which the parent classes are listed.
     
    27782778...     haircut_type = CharField()
    27792779>>> b = Beatle(auto_id=False)
    27802780>>> print b.as_ul()
    2781 <li>First name: <input type="text" name="first_name" /></li>
    2782 <li>Last name: <input type="text" name="last_name" /></li>
    2783 <li>Birthday: <input type="text" name="birthday" /></li>
    2784 <li>Instrument: <input type="text" name="instrument" /></li>
    2785 <li>Haircut type: <input type="text" name="haircut_type" /></li>
     2781<li class="required">First name: <input type="text" name="first_name" /></li>
     2782<li class="required">Last name: <input type="text" name="last_name" /></li>
     2783<li class="required">Birthday: <input type="text" name="birthday" /></li>
     2784<li class="required">Instrument: <input type="text" name="instrument" /></li>
     2785<li class="required">Haircut type: <input type="text" name="haircut_type" /></li>
    27862786
    27872787# Forms with prefixes #########################################################
    27882788
     
    28042804... }
    28052805>>> p = Person(data, prefix='person1')
    28062806>>> print p.as_ul()
    2807 <li><label for="id_person1-first_name">First name:</label> <input type="text" name="person1-first_name" value="John" id="id_person1-first_name" /></li>
    2808 <li><label for="id_person1-last_name">Last name:</label> <input type="text" name="person1-last_name" value="Lennon" id="id_person1-last_name" /></li>
    2809 <li><label for="id_person1-birthday">Birthday:</label> <input type="text" name="person1-birthday" value="1940-10-9" id="id_person1-birthday" /></li>
     2807<li class="required"><label for="id_person1-first_name">First name:</label> <input type="text" name="person1-first_name" value="John" id="id_person1-first_name" /></li>
     2808<li class="required"><label for="id_person1-last_name">Last name:</label> <input type="text" name="person1-last_name" value="Lennon" id="id_person1-last_name" /></li>
     2809<li class="required"><label for="id_person1-birthday">Birthday:</label> <input type="text" name="person1-birthday" value="1940-10-9" id="id_person1-birthday" /></li>
    28102810>>> print p['first_name']
    28112811<input type="text" name="person1-first_name" value="John" id="id_person1-first_name" />
    28122812>>> print p['last_name']
     
    28812881...         return self.prefix and '%s-prefix-%s' % (self.prefix, field_name) or field_name
    28822882>>> p = Person(prefix='foo')
    28832883>>> print p.as_ul()
    2884 <li><label for="id_foo-prefix-first_name">First name:</label> <input type="text" name="foo-prefix-first_name" id="id_foo-prefix-first_name" /></li>
    2885 <li><label for="id_foo-prefix-last_name">Last name:</label> <input type="text" name="foo-prefix-last_name" id="id_foo-prefix-last_name" /></li>
    2886 <li><label for="id_foo-prefix-birthday">Birthday:</label> <input type="text" name="foo-prefix-birthday" id="id_foo-prefix-birthday" /></li>
     2884<li class="required"><label for="id_foo-prefix-first_name">First name:</label> <input type="text" name="foo-prefix-first_name" id="id_foo-prefix-first_name" /></li>
     2885<li class="required"><label for="id_foo-prefix-last_name">Last name:</label> <input type="text" name="foo-prefix-last_name" id="id_foo-prefix-last_name" /></li>
     2886<li class="required"><label for="id_foo-prefix-birthday">Birthday:</label> <input type="text" name="foo-prefix-birthday" id="id_foo-prefix-birthday" /></li>
    28872887>>> data = {
    28882888...     'foo-prefix-first_name': u'John',
    28892889...     'foo-prefix-last_name': u'Lennon',
     
    29712971>>> print my_function('GET', {})
    29722972<form action="" method="post">
    29732973<table>
    2974 <tr><th>Username:</th><td><input type="text" name="username" maxlength="10" /></td></tr>
    2975 <tr><th>Password1:</th><td><input type="password" name="password1" /></td></tr>
    2976 <tr><th>Password2:</th><td><input type="password" name="password2" /></td></tr>
     2974<tr class="required"><th>Username:</th><td><input type="text" name="username" maxlength="10" /></td></tr>
     2975<tr class="required"><th>Password1:</th><td><input type="password" name="password1" /></td></tr>
     2976<tr class="required"><th>Password2:</th><td><input type="password" name="password2" /></td></tr>
    29772977</table>
    29782978<input type="submit" />
    29792979</form>
     
    29832983<form action="" method="post">
    29842984<table>
    29852985<tr><td colspan="2"><ul class="errorlist"><li>Please make sure your passwords match.</li></ul></td></tr>
    2986 <tr><th>Username:</th><td><ul class="errorlist"><li>Ensure this value has at most 10 characters.</li></ul><input type="text" name="username" value="this-is-a-long-username" maxlength="10" /></td></tr>
    2987 <tr><th>Password1:</th><td><input type="password" name="password1" value="foo" /></td></tr>
    2988 <tr><th>Password2:</th><td><input type="password" name="password2" value="bar" /></td></tr>
     2986<tr class="error required"><th>Username:</th><td><ul class="errorlist"><li>Ensure this value has at most 10 characters.</li></ul><input type="text" name="username" value="this-is-a-long-username" maxlength="10" /></td></tr>
     2987<tr class="required"><th>Password1:</th><td><input type="password" name="password1" value="foo" /></td></tr>
     2988<tr class="required"><th>Password2:</th><td><input type="password" name="password2" value="bar" /></td></tr>
    29892989</table>
    29902990<input type="submit" />
    29912991</form>
Back to Top