Magnetic fields in molecular clouds