|
Form Error Messages in the Right PlaceOverviewThe JHTML form wizard adds a block of code to display form errors at the top of the form. It iterates over any form errors and displays the errors in a list. This article shows you how to place your error messages next to the form field which generated them. ExampleDefault Form Error Message Handling
Custom Form Error Message Handling
How to do Custom Form Error Message HandlingCode SampleHere's the JHTML code for the First name field in the form above. <tr>
<td class="label">First name:*</td>
<td>
<DROPLET BEAN="/atg/dynamo/droplet/IsNull">
<PARAM NAME="value" value="bean:ProfileFormHandler.propertyExceptions.firstName">
<OPARAM NAME="false">
<font color=red>Please enter your name</font><br>
</OPARAM>
</DROPLET>
<INPUT class="content" TYPE="TEXT" NAME="firstName" SIZE="24"
BEAN="ProfileFormHandler.value.firstName" REQUIRED><BR>
</td>
</tr>
We check to see if there is a value in the FormHandler's propertyExceptions map for the field firstName. If there is then we display and error message "Please enter your name" just above the form field. Simply repeat this process for each form field in your form. NOTE: The key in the propertyExceptions map is the name of the property specified in the BEAN= tag of the input field. When you are done, don't forget: You may need to remove the error message for each at the top of your form. |