Liquid soap dispenser always layed in the sink with the nozzle facing up when traveling... never leaked.
Medicine cabinet: Unless yours if very deep & most aren't, you just have to put things in there so there's no room to fall over. Load it up!
Other cabinets: A plastic shoebox size labeled for specific items such as 'first-aid', 'colds', 'extra toothpaste, brushes, floss', etc. works. Keep things of the same use together & they'll be easy to grab. The boxes can be easily stored under the sink. You don't use them very much.
Consider small trays with sides from WalMart, etc. Something like 5"x2" or whatever size your shelf is. Things will stay in it good.