fix bug with forms where data and ui have different hierarchies

and add tests

fixes: http://manage.dimagi.com/default.asp?117610
Comment doesn't seem to match with line below. I understand the comment to be saying "remove path[2:]".