0

OK I guess it's not a matter of scrambling as much as encoding... But when I take HTML from a form field and pass it through jQuery serialize, all the special characters get changed so if I want to output the HTML as actual HTML to be rendered as such in browser, what is the easiest way?

So this...

<div id="object_01" class="object_textbox ui-draggable ui-resizable" namn="object_01" style="z-index: 1; font-family: Arial;"><div class="object_inner" style="border:solid 1px #000;background-color:#fff;border-radius:100%;"></div><div class="ui-resizable-handle ui-resizable-e" style="z-index: 1000;"></div><div class="ui-resizable-handle ui-resizable-s" style="z-index: 1000;"></div><div class="ui-resizable-handle ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se" style="z-index: 1000;"></div></div>

Turns something like...

%0D%0A%09%09%3Cdiv+id%3D%22object_01%22+class%3D%22object_textbox%22+namn%3D%22object_01%22+style%3D%22z-index%3A+1%3B+font-family%3A+Arial%3B%22%3E%3Cdiv+class%3D%22object_inner%22+style%3D%22border%3A+1px+solid+rgb(0%2C+0%2C+0)%3B+background-color%3A+rgb(255%2C+255%2C+255)%3B+border-top-left-radius%3A+100%25%3B+border-top-right-radius%3A+100%25%3B+border-bottom-right-radius%3A+100%25%3B+border-bottom-left-radius%3A+100%25%3B+cursor%3A+move%3B%22%3E%3C%2Fdiv%3E%3C%2Fdiv%3E
Matt Welander
  • 8,234
  • 24
  • 88
  • 138
  • is the php urldecode() the proper way? http://www.php.net/manual/en/function.urldecode.php – Matt Welander Jun 13 '14 at 09:31
  • Yes, that's the correct function. But PHP should do that automatically for you when it sets the variables `$_POST` or `$_GET` from the parameters. – Barmar Jun 13 '14 at 09:33
  • oh ok, but I am using serialize() in a little unconventional manner, I pick up the entire form and store it in a form field on that form, as part of the submit event. I do this because I want to pick up an unknown number of form fields from the form, search them out by name. – Matt Welander Jun 13 '14 at 09:40
  • You could just store the HTML itself in the form field. When the form is submitted, the browser or jQuery will encode the field, and PHP will decode it. – Barmar Jun 13 '14 at 09:43
  • yes, but there is a bunch of form fields and html is only one type of contents they may have. These actual fields are defined in a separate template file which I have no control over, so I have to sort of loop over these fields by name and pick up the ones with the certain name-prefix. – Matt Welander Jun 13 '14 at 09:51

1 Answers1

0

As the comment trail on this question suggests, the php method urldecode() is the way to restore all spoecial chars to the string for HTML rendering.

Matt Welander
  • 8,234
  • 24
  • 88
  • 138