apostrophe issue with serialization on a form in PHP / Jquery

153 views Asked by At

I have an issue with an apostrophe that maybe someone can help me out with. The project is a PHP project using the Smarty template system. The code that I have to deal with is about getting data as a hidden type into a form when a pop up loads. When people add instructions with an apostrophe there is a crash - I believe because there is an opening ' and then the instructions have an ' which cuts off the rest of the needed data.

Here is the line of code that takes the $test_data:

$html .= "<input type=hidden value='" . $test_data . "' id=test_data name=test_data />";

Here is what the $test_data variable looks like:

{"pathway":"Rapid","device":{"2410":{"requires_two_factor":true,
"instructions":"doesn't work",
"comments":"doesn't work",
"message_xml":"TQ1JJUFQiIERhdGF0eXBlc1ZlcnNCiAgPC9Cb2R5Pgo8L01lc3NhZ2U+"}}}

And here is what it looks like using inspector or dev_tools, in the actual HTML:

<input
type=hidden
value='{"pathway":"Rapid","device":{"2410":{"requires_two_factor":true,
"instructions":"doesn't work",
"comments":"doesn't work",
"message_xml":"TQ1JJUFQiIERhdGF0eXBlc1ZlcnNCiAgPC9Cb2R5Pgo8L01lc3NhZ2U+"}}}'
id=test_data name=test_data />

What I think the issue is the '{" at the start and then the first doesn't work breaks it with that second apostrophe. Is there any way around this? Do I have the $html set up correctly? Thank you for any help.

0

There are 0 answers