Re: CUSTOM and SUBMIT

Joel Palmius <[email protected]> Tue, 15 Nov 2005 13:21:13 +0100 (CET)
Newsgroups gmane.comp.apache.mod-survey.general
Message-ID <[email protected]>
On Mon, 14 Nov 2005, Dietrich J Kappe wrote:

> Two questions:
>
> 1. Is there a prefered way to repopulate the values of fields in a CUSTOM
> tag? Trying to insert variables the first time through doesn't seem to work.
> Time for some preparse perl snippets?

I don't understand what you mean by "repopulate". Did you have earlier 
data?

> 2. I've been eyeing the SUBMIT tag for a way of further validating fields,
> for example, if a field is supposed to be a zipcode, I'd like to check if it
> is 5 digits. If not, I want to issue an error and drop into the usual
> mod_survey error handling.
>
> Could there be an opportunity for a validation component here?

I think I did some basic code here actually. Idea was that return value of 
a perl snippet should decide if the commit was acceptable. I don't think 
this works though.

However, I'd recommend validating at the time of input. You can make a 
CUSTOM with a variable, which implements a text field with javascript 
checking of the input. You can trigger the check on an onExit from the 
text field, and clear it if the input is erronous. Something like

<SURVEY ...>

   <CUSTOM VARIABLES="zipcode" ESCAPED="no">

     <script>
       function checkZip()
       {
         ...
       }
     </script>

     <input type="text" name="zipcode" onExit="checkZip()" />

   </CUSTOM>
</SURVEY>

Possibly you could also override the onSubmit event for the form of the 
page to perform extra javascript checks. I haven't looked into how this 
could be done.

> One suggestion for an improvement: rather than pop to a seperate page that
> tells you that you have a problem and encourages you to hit the back button,
> why not just redisplay the survey page with a little error message up top?
> If not, then at least give the user a back link on the page:  <a
> href="javascript:history.back(1)">back</a>

Yup, exists and looks pretty ok in devel branch.

   // Joel
Skickat av Joel Palmius <[email protected]>
till survey-discussion