Formation of negative ions in magnetic fields