I haven't used it myself, but this sounds like what CGI::FormBuilder does.
In reply to Re: Form Validation Ideas by kyle in thread Form Validation Ideas by Trihedralguy