[ZPT] Highlighting bad data fields in Formulator

Tom P. Allred tom at allreddata.com
Mon Sep 8 12:07:55 EDT 2003


Hi,

It seems like I've seen this question in the mailing list before but
couldn't find it when I searched.  I'm currently using code from a
Formulator example to display input errors to the user.  Here is the code
from the python 'formaction' script.

# Here we'll catch errors
try:
  result = context.dataform.validate_all(context.REQUEST)
except FormValidationError, errlist:
  print "<font style='font: 17px'>I'm sorry. Some of the information you
entered was either incorrect or incomplete. Please use the &quot;back&quot;
button and fill it in correctly. Thank you!<br><br>"
  for error in errlist.errors:
    print '<b>' + error.field.get_value('title') + ': '+ error.error_text +
'</b><br>'
  print '</font>'
  return printed

What I'd like to do instead is re-display the input form with highlighted
(say red) field labels and a message at the top asking the user to fix the
highlighted fields and re-submit.  Here is the code displaying the fields,
again taken from an example.  It is defined in a macro called by the
folder's index_html.

<!-- This starts the table that displays all fields on the form --->
<table tal:define="form here/dataform" align=left>
  <!-- Loop through the Formulator field ids to get the form fields --->
  <tr tal:repeat="itemz here/dataform/get_field_ids">
  <!-- Using span to define a block definition to hold a form field
object --->
  <span tal:define="fieldobj python:form.get_field(id=itemz)">
   <th align="left">
    <font size=4>
     <font face="verdana">
      <!-- Get/Display the title property of the current input field --->
      <b tal:content="fieldobj/title">Field Display Label</b>
      <b>:</b>
     </font>
    </font>
   </th>
   <td>
    <!-- Use Formulator render command to create the field data input
box --->
    <input type="text" name="itemz"
        tal:replace="structure python:fieldobj.render()">
   </td>
 </span>
 </tr>

It seems like the 'formaction' script will need to set some values for the
error fields that the ZPT will use to set their label color.  Any
suggestions on how to do this?

Thanks,
Tom P. Allred
Tom at AllredData.com





More information about the ZPT mailing list