Implementing settings API pattern as explained in this post - http://kovshenin.com/2012/the-wordpress-settings-api/.