Brush away any loose foam or other debris from the surface of the foam mattress piece.
Apply a thin layer of adhesive to the foam mattress piece. Glue guns and spray adhesives are ideal for gluing polyurethane foam. Other glues may melt or tear the foam. For a long-lasting, secure bond between two foam pieces, try a specialized foam adhesive like 3M's Fastbond Foam Adhesive.
Attach the foam mattress piece (or pieces). Apply pressure for roughly 15 to 30 seconds, or follow the manufacturer's instructions for set times.