Refactored the logic to get the form field

This extracts some logic to reduce the complexity of the method. There is
also a few benefits:

- computing the position is now done only when it is actually needed (most
  fields will probably not need it), thus avoiding an xpath query in most
  cases
- the logic to find the form element for a field can now be reused for
  other elements, as needed in #41
Fixed a typehint

The methods hasAttribute and getAttribute only exist in DOMElement, not in
DOMNode.
Improved some phpdoc
Merge pull request #47 from stof/simplify_form_id

Refactored the logic to get the form field