The advice Sadielynn gave is good, but I'll add that if you have pad under that carpet you most likely aren't going to dry it from the top down. 4 gallons, when spilled, is a LOT of water! And if that pad is wet and stays wet, you're going to have a mildew/mold problem. It'll take a while to notice, but if you don't get that pad under the carpet dried totally, you're going to have a smelly mess in a few months.
When I've had water leaks (not aquarium related!), I've pulled the carpet up and got under to the pad and dried everything from the bottom up. Force air under the pads to dry everything out. It's a real pain, but I wouldn't take lightly 4 gallons of water soaked into who knows where.