Avoid error if a field doesn't exist, fixes #4879

Squashed commit of the following:

commit 94739ec246e8ef85025531308f09e8d5721e55bc
Author: Jesús García Crespo <jesus@sevein.com>
Date:   Tue Apr 2 18:04:18 2013 -0700

    Check if the field exists before using it

commit c4fe5751f92ea69c99fa3bb6b9cdd0e873417cbd
Author: Jesús García Crespo <jesus@sevein.com>
Date:   Tue Apr 2 18:03:48 2013 -0700

    Add isset magic method to Document