Another phalanx tip I found in another thread for keeping the formation intact while attacking was to order the phalanx unit to move to a position directly behind the target unit, rather than ordering them to attack the target unit normally. (sorry I don't remember who originally suggested this)