Fortunately, there is another way. Go into the Settings application and tap on "Cellular Data." This brings up an on/off switch for Cellular Data and Data Roaming. Turn both "off" and you will not be prompted to sign up for a data plan when Wi-Fi is unavailable.
Airplane mode disables not only the cellular data, but also Wi-Fi, Bluetooth, and the GPS. If you are only trying to avoid using cellular data, there's no need to use Airplane Mode.
If you have upgraded your iPhone to iOS 4 then you also have the ability to disable cellular data under Settings » General » Network » Cellular Data, which may come in handy if you have a metered account with AT&T.