Use a stud finder to locate two studs in the wall behind your bed, where you want the headboard to go. Mark the studs with a pencil, at the height where you want to hang the foam board headboard. Use a level to make sure the marks are level.
Hammer one nail into each mark, leaving 1/4 inch jutting out of the wall. Measure the distance between the two nails with measuring tape and transfer the measurement to the back of the headboard, 1 inch from the top edge.
Remove the adhesive backing from the back of the two D-rings if using foam board only and press them into the marks you made on the back of the headboard. Use standard D-rings that screw into the wood if using backer board with your foam board. Lift the headboard and mount the D-rings over the two nails.