My 6 yr old son has suffered constipation since he was about 2 years old. In his case, his world got turned upside down around then (I left my abusive ex-husband and filed for divorce).
My son's flare ups seem to coinside with any stress or major change - starting school, changing babysitters, traveling...
it's something he can control (by holding) when everything else seems out of his control. He also had embarassment issues because he needed help wiping after a bowel movement and was embarassed asking for help - so he would just hold it instead.
My former mother in law took my son to the doctor a few years ago and had him put on a prescription stool softener (without my knowledge). Once I found out about it, I took him off of it.
I control my son's bowel movements through diet. Foods high in fiber help keep everything moving smoothly. Most people think grains when they think of fiber, but there are other types of fiber. Pears are very high in fiber (a medium sized pear has about 5 grams of fiber). Other high-fiber foods are apples (with skin), blueberries, raisins, oranges, peaches, whole-wheat spagetti, oatmeal. Lentils, black beans, and lima beans all have at LEAST 13 grams of fiber per one cup serving (an adult, muchless a child wouldn't eat that much in a single serving, but smaller amounts over a period of of a couple of days helps too). Peas, baked potatoes (with skin), carrots, corn, brussel sprouts are all good sources of fiber, too.
I'm not sure what the recommended fiber intake is for children - women is 21-25 grams per day and men is 30-38 grams per day. For my son, I aim to get about 7-10 grams a day (some days are far less and other days we blow that out of the water, it just depends).
It might be worthwhile to see if your daughter has any triggers. My son's BM issues are induced by stress or major change of any kind (even good ones, like my mom visiting for a week, through him off). Since I know my son tends to hold when theres a lot of activity going on, I try to increase his fiber for a few days before a major event or change. I also give him belly rubs and let him soak in a long warm bath to help relax his muscles.
good luck... it can be frustrating - especially when they have "accidents" (whatever manages to leak out past what they are holding).