My question is actually twofold: One, the question in the title. Was the strategy of charging the enemy formation to overrun them with infantry ever used in any shape or form as movies tend to portray it? Did infantry ever charge at all?
Secondly, knowing that unlike what movies tend to show us, spears (Not swords) were the primary weapon of most infantry throughout most of history, would infantry ever charge the enemy with their spears similarly to knights with lances?
I don't really know to begin but when it comes to infantry charging other infantry using spears; this was done regularly, in disciplined formation. Speaking about the late medieval and early modern era, pike formations of the Swiss, and German Landsknechts, were sufficiently disciplined and well drilled that they could charge and maintain formation. This is what made them extremely deadly. See the Battle of Grandson as an example, or Cerignola, both in the late medieval Burgundian and Italian ward.
You will have to be more precise in what you are asking, there are thousands of movies depicting this and we can't give a survey review of every single one of them.
Are we including infantry charges such as those in trench warfare? What about bayonet charges such as those used in the falklands war and more recently?