To remove urine odor from foam, soak up as much of the urine as possible while it is still wet, and then treat the foam with a diluted vinegar solution. Absorb the vinegar with a towel, and sprinkle the spot with baking soda. Leave the baking soda in place overnight, and vacuum the spot the next morning.
To make the vinegar solution, mix equal portions of distilled white vinegar and water. Place the mixture in a spray bottle for easy application.
When attempting to clean urine from normal mattresses, it is important to avoid pressing on the mattress, since this may press the liquid deeper into the mattress. With foam, there is less chance of this happening. Avoid saturating the foam with the vinegar solution, but instead spray a small amount of the solution, and then use an absorbent towel to remove as much as possible. Change towels frequently to remove as much liquid as possible.
Sometimes urine odors return several days after cleaning. Treat the foam again using the vinegar and baking soda process. If the urine smell persists, purchase enzymatic urine odor remover from the pet store, and treat the foam according to the label directions. If the foam in question is a foam mattress, such as memory foam, prevent future accidents by protecting the mattress with a removable mattress protector.