Search code examples
character-encodingspecial-charactershtml-encode

Prevent HTML Decoding on Form Values


I have a form element such as: <input type="text" value="O&rsquo;Reilly" />

But when this form is submitted, the value passed to the form handler is decoded and the ’ character is sent instead of the original string &rsquo;

I need to get the original string in it's literal/raw form, but I cannot seem to force the page to stop decoding these HTML elements for me. Any ideas?


Solution

  • HTML-encode the ampersand with &amp; to prevent it from being part of an escape sequence: <input type="text" value="O&amp;rsquo;Reilly" />