The World Federation One Stop Fiqh

Ruling 1093

If a person forgets the salām of the prayer and remembers it after the form of the prayer has broken up, or if he has intentionally or inadvertently done something that would invalidate his prayer – such as turning his back to qibla – then his prayer is valid.