Plenty of foam, although messy, is not a bad thing as it indicates healthy yeast and a strong fermentation. Excess foaming is more likely to occur when using ale yeast with darker brews and higher fermentation temperatures. Also seasonal variations may affect the barley (main ingredient in beer apart from water) causing more foam. To avoid foaming over allow for extra headspace by using a bigger fermenting tub or fill to a lower level (around 18-20 litre mark) then top up with cool boiled water after initial foaming has subsided (normally after a day or two).