Forum OpenACS Q&A: Re: How to know if there's an error in a form (template level)

Hi Jim,

Yeah, I've been quite busy with other things lately but never stopped reading the forums :).

I'm using ad_form and I didn't want to use ad_complain or ad_returnerror that would abort the process. Since ad_form handles validation, I wanted to take advantage of it. My problem was a usability issue: the form is long enough to have to scroll to get to the last fields. If the user doesn't respond mandatory questions that are at the bottom, the error messages will appear next to those fields and the user won't be aware there was an error until she scrolls down, that's why I want to insert a message at the top of the template.

So in the Tcl, I have the usual ad_form declaration, and the adp is:

    <property name="doc(title)">@page_title@</property>
    <formtemplate id="survey" style="custom-form-template"></formtemplate>

The custom-form-template.adp is a copy of acs-templating/resources/forms/standard.adp with a few minor changes plus the insertion I mentioned in my previous message. The message string is hard coded in the template for now, it could be a message key also, but predefined anyway. The result is not that elegant because the message is not inserted before the form but in between the hidden fields after the form tag:

<form id="survey" name="survey" method="post" action="survey" class="vertical-form">
<div><input type="hidden" name="form:mode" value="edit" ></div>
<div><input type="hidden" name="form:id" value="survey" ></div>
<div class="form-error">Error message goes here</div>  <====
<div><input type="hidden" name="__confirmed_p" value="0" ></div>

I guess a better way would be to extend ad_form and the form processor to include the error flag and message in the form structure and render it in a more convenient place of the HTML document but for my current need the solution I've found is good enough.