As others have suggested, you might like to look at using CGI as well as javascript to validate the user's input. Since you're new to CGI, I would recommend reading
Ovid's CGI Course particularly
Chapter Three which is all about security, checking user input and making sure that the input you allow will not mean people can do evil things to you - the first rule of CGI programming is assume that all your users are evil! ;)
The excellent book Beginning Perl also has an Introduction to CGI which doesn't mention javascript but is still pretty useful.