Your function implicitly assumes the input will be a string; however, when you make a choice in your form “a” is returned as an entity and not as a string.
You need to reformulate your planetDistance function to operate on an entity rather than a string.