"You've got to nip it in the bud!"
Toddlers that are being potty trained do not yet have the development to “hold it” until you get inside. This is actually a learned skill and there will be times you just can’t get them to the toilet. I can’t think of a child who has not had an “accident” or who hasn’t had to go behind a tree from time to time.