JSON data in text field being changed

Status
Not open for further replies.

rackem

Well-Known Member
I save JSON data to a text field using some Form PHP. For example,
{"p1":28,"p2":29,"s1":5,"s2":4,"t_id":1,"g_id":1}

However, if that record is ever edited later, the JSON example above is changed to
{"p1":28,"p2":29,"s1":5,"s2":4,"t_id":1,"g_id":1}

which obviously won't work in a json_decode(). I also tried a Field element and got the same results.

My element's edit & view ACL is set to nobody. I am just using the element to backup the form info to compare against to check if any edits were made.

Is this intended behavior? Is there a way to prevent Fabrik from changing this data?
 
Hmmm, I think it's the result of a recent change where we're trying to normalize how quotes get stored. I guess we didn't think about people storing and processing JSON themselves.

I can't really think of any automated solution for this, as we can't really start making exceptions about what we encode and what we don't, as that kind of defeats the object of normalizing.

I think the only solution is to decode the value yourself, so ...

PHP:
$json = json_decode(htmlspecialchars_decode($value));

... which should handle either case.

What I'm not sure about is why it's not getting encoded on the first write, only on edit.

rob ?

-- hugh
 
Your suggestion worked perfectly Hugh, thank you! :)

What I'm not sure about is why it's not getting encoded on the first write, only on edit.
Sorry to get you wondering, that was me. I was having problems getting the $formModel->updateFormData() approach working in my Form PHP so I was inserting it myself using MySQL. Which, when I first tried your suggestion, was creating even more problems with double encoding or something. Anyway, I had an "ah, ha!" moment :D and got the $formModel->updateFormData() figured out, which coupled with your suggestion, made me feel like *life is good*:cool: with this code!
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top