There are 2 common reasons for foaming,
During the start up phase- white foam occur when there is more food and less micro organisms in the reactor. This would subside with time (4- 10 days) when the FM ratio reaches optimal levels in the reactor. This is a positive sign of activated sludge formation.
Dark foam in older plants- This is due to long sludge aging. This can be rectified by having an active sludge recirculation to anoxic chamber or removing of excessive sludge from the reactor.
There could be other reasons like excessive usage of detergent in new constructions during flooring and interior works. Care should be taken that the sewage treatment plant is not exposed to any abnormal condition. Filamentous bacteria are the cause of foaming when foaming occur often. Technical expert review and control mechanisms are recommended.