Contact Forms: Extract anonymous functions for bc.

Extracted anonymous functions from `replace_tokens_with_input` as static
methods for PHP backwards compatibility.