Restricting User input

Hi Folks,

I’ve got a basic setup where users can submit to a notice board, a title, body text and a image.

Typically, the text can have special charactors which breaks my pages, and the images are always way to big.

Are there any client side techologies that I could use to tell if images were too big and if a string had special charactors in it?

Many thanks

Imagemagick for images, you can make thumbnails:
http://www.imagemagick.org/Usage/thumbnails/

Plain old PHP (or whatever you’re using) for the text validation. Maybe take a look at regular expressions: http://www.webcheatsheet.com/php/regular_expressions.php

Good luck with it!

There is no magic solution. You’ll have to write server side code to this properly.

When the user submits the form, validate the contents and only allow special characters you want to allow. If you are allowing users to submit html, then be very thorough in validating the content, otherwise your vulnerable to every hacker out there. Coldfusion has several functions that will help convert characters in the text to html characters so they display properly and also breaks any script a hacker might be trying to insert.

As far as the images go, there are several CF functions that you can use to allow them to upload the image, validate the type of file, check the image size and resize the image if necessary. Check out the cffile and cfimage functions.

CFFile allows you to upload the image. You can also restrict which type of files can be uploaded, so if you only want gif and jpg, you can filter everything else out.

Using cfimage, you can get the image’s properties, then scale or resize the image to the correct dimensions. You can also convert images to other formats and optimize images.

As Lemonizer already mentioned there are many build in functions in CF to deal with replacing characters and the same goes for image dimensions, at least if you are using CF8 >. For older versions you can of course limit the file in bytes but that’s no guarantee. There are quite some nice custom tags around at CF Library .