Remove the door from the hinges by unscrewing the hinges. Take the door down. Place the door on a flat surface. Place the hardware in a plastic bag to keep it all together.
Remove any splinters or excess wood from the hole. Use a utility knife to pare them away. Put on gloves and clear the rest out with your hand.
Shake the can of expanding foam and hold it upside down. Spray the foam into the hole. Do not overspray -- it will expand quickly. Fill in the entire area. Let this dry for at least two hours.
Use a utility knife to pare away any excess foam. It should be flush or just a little below the surface of the door.
Spackle over the hole using a trowel or a putty knife. Joint compound works as well. Cover the hole completely and scrape off any excess with the edge of your knife.
Sand down the patch. The surface of the patch should be smooth to the touch and level with the rest of the door. Use a fine-grade sandpaper. A sanding block works very well for this application.
Sand over the entire surface of the door with a fine grade of sandpaper or your block. Prime it with an oil-based primer. Let this dry for four hours. Paint over the primer with the paint color of your choice. Use an oil-based latex. Let this dry completely and flip the door over to paint the other side. Rehang the door.