The solution to that is to move your men out of Phalanx until they get close to the enemy.

You may have noticed that when horse run through your formations they don't do it in a nice way... They knock your men over and push them out of the way, well you can imagine what trying to run through a tight Phalanx would do!

I have never lost a general like this but I have taken casualties from it. Just tell your guys to get out of Phalanx and "watch where your pointing that mate!", spears held upright are always safer.