Spread out a length of foam batting flat on a work surface. Place your headboard front-side-down on top, and cut the batting around 10 inches out from the edges of the headboard.
Pull the edges of the batting up and over the back of the headboard frame, and staple it in place at the back. Make hospital corners with the batting at the corners so they are neat.
Spread out your fabric wrong-side up on the work surface, and iron it flat. Center the headboard frame with the batting side face-down over the fabric.
Pull the edges of the fabric up over the back of the headboard in the same way you did for the batting, but pin the fabric in place. Take a look at the front of the headboard and make sure the fabric is positioned the way you want it. The pattern should be where it's supposed to be, and any lines should be straight. Adjust as needed.
Staple the fabric to the back of the headboard frame once you are happy with the placement. Then remove the pins, and trim the excess fabric with scissors. You can now reattach your newly upholstered headboard frame to the bed.