Many changes to improve field validation in the form and prevent config file corruption.

Have added extensive checking of the configuration fields. If a field
that is essential is left blank, then the default (and sensible) value
is now saved. This also prevents the configuration file getting
corrupted due to the way that empty fields were not correctly saved.