There are no legal mechanisms that would prevent a president from fighting.
There is nothing to stop a President from fighting in a war. But you have to ask the question what would be the effect on morale if the President was killed or captured?
The last sitting President to actually engage in combat was President James Monroe during the War of 1812 and the last sitting President to come under fire was President Lincoln during the "American Civil War".
In history George Washington did in fact go out into the field with his troops during the Whiskey Rebellion.
Washington got Congress to pass a Conscription act to fill out this force, to 12,950 soldiers. Washington inspected these troops in Harrisburg PA, held a meeting with his federal agents in Bedfored PA, to establish a policy that would defuse the situation. Then Washington inspected another wing of the army in Cumberland Maryland. Washington did not lead this army over the mountains or into battle.
Once it got to western Pennsylvania there wasn't much of a battle anyway.
But for todays troops presidents going out into the battlefield leading their troops is too risky, the amount of snipers, landmines and modern equipment makes it almost impossible for them to survive.
Olden kings used to ride out into battle but they weren't front line; infact they were at the back surrounded by foot soldiers and archers. Try that today and a sniper rifle or a blown into bits by a B-52
I would say if Independence Day happened in real life the president would probably at most just wave goodbye and/or give a handshake and a medal of bravery to the brave soldier that takes off to fight for his country.
But since its a movie my guess is that they did this scene to make the American president look like a hero or some sort.