It might seem complicated, but the answer is actually very simple. Use “to” when the reason or purpose is a verb. Use “for” when the reason or purpose is a noun.