Oh I do sympathise, we have just been through the same upsetting episode.
I picked ds (4) up from school one day and the smell was instant, I was so worried that his friends may have noticed. When I got him home, I had to wash him down and his hands were also fifthy. He explained that he had had an accident and had not told his teacher but hobbled to his PE bag, covertly taken out his spare pants, and changed himself in the loo himself. My heart bled for him.
He had had difficulty going to the loo for a while, and I think that the constipation had caused a tear in his bottom, which was bleeding and making him fearful to go to the loo, so he was holding in until the last possible moment, hence the accident when he left it too late.
I went to GP,Lactose did not make a jot of different but Movocol (2 times a day) sorted the problem immediately. I was worried that it would cause diarrhea but it did not, it just softened the stools and made him easier to go, no more accidents, and so wld recommend you start it immediately.
Also told teacher, but in a class of 30, not sure that they have the time to look out for these issues, as sad as this is for us.
Ps. We later discovered ds had threadworms which may have caused the cut to his bottom, through scratching.