Context. The ultraviolet irradiation and the action of stellar winds of newly formed massive stars on their parental molecular environment often produces isolated or small clouds, some of which become sites of star formation themselves. Aims. We investigate the young stellar populations associated with DR 18 and ECX 6-21, which are two isolated globules irradiated by the O-type stars of the Cygnus OB2 association. Both are HII regions containing obvious tracers of recent and ongoing star formation. We also study smaller isolated molecular structures in their surroundings. Methods. We combined near-infrared broad- and narrow-band imaging with broad-band imaging in the visible and with archive images obtained with the Spitzer Space Telescope. We used the joint photometry to select young stellar objects (YSOs), simultaneously estimating their intrinsic properties and classifying them according to the characteristics of their infrared excess. We also present low-resolution visible spectroscopy of selected sources. Results. We reproduce previous findings of an extended population of YSOs around both globules, dominated by the more evolved classes, associated with the general Cygnus OB2 population. Both globules contain their own embedded populations, with a higher fraction of the less-evolved classes. Masses and temperatures are estimated under the assumption of a common age of 1 Myr, which has been found to appropriately represent the general Cygnus OB2 YSO population but is most probably an overestimate for both globules, especially ECX 6-21. The early-B star responsible for the erosion of DR 18 is found to be part of a small aggregate of intermediate-mass stars still embedded in the cloud, which probably contains a second site of recent star formation, also with intermediate-mass stars. We confirm the two main star forming sites embedded in ECX 6-21 described in previous works, with the southern site being more evolved than the northern site. We also discuss the small globule ECX 6-21-W (=G79.8 + 1.2), and propose that its non thermal radio spectrum is due to synchrotron emission from an embedded jet, whose existence is suggested by our observations. Conclusions. The extreme youth of some of the YSOs suggests that star formation in both globules started after they became externally irradiated. The populations of both globules are not found to be particularly rich, but they contain stars with estimated masses similar or above that of the Sun in numbers that hint at some differences with respect to the star formation process taking place in more quiescent regions where low-mass stars dominate, which deeper observations may confirm.