Seems to me that she needs toilet training or a complete evaluation done by pediatrician to eliminate potential causes,if the problem has been repeating once.Medical issues may have symptoms but if your child is asymptomatic then consider counseling with a pediatrician and learn about controlling it.Wish you good luck.
Have her evaluated by her pediatrician before considering discipline. There very well could be a medical or emotional issue that could be contributing to this behavior.