Hurray for gate springs! They are an inexpensive (~$11) way to make sure your gate closes and latches anytime someone opens it. This a a great way to keep your dog safe without having to rely on people actually remembering to make sure the gate is closed.
Gate springs can be found at most hardware stores and are really easy to install. Use some care in adjusting the tension on the screw.