Onion bolting occurs when onions have decided to send up a flower stalk and go to seed, which happens for the following reasons:
In all these cases, the bolting onion thinks it's going to die before it can bulb, so it puts all its energy into trying to make seeds right away instead.
Some folks will tell you to just bend over the flower stalk when it forms, or to just prune them off. I've even read that you should bend over all the green tops.
But once onion bolting starts, onions cannot be convinced otherwise and it’s best to dig them up for immediate eating as “green onions”. Bolting onions will only very rarely recover and form a large bulb, and even if they do, the bulb storage quality will be low. This is because the plant took the energy from the bulb and used it to send up the flower stalk.
To keep onions from bolting in the first place, protect them over an extended cold, wet spell by covering them. The best way is with a little hoop tunnel, which keeps them out of the weather entirely and can easily add 10 degrees of temperature.
Alternatively you could cover them with Reemay (or other brand) floating row cover. This is let involved, but doesn't work as well.
And if the weather turns suddenly hot, make sure to keep your onions evenly watered. The soils needs to stay loose and friable. If it starts to get that baked-hard quality, onions will bolt because they can't expand.
To learn more about growing onions check out these related articles: