0

I'm using Malsup's jQuery Form Plugin. I'm sending the form back to be validated and trying to return a JSON response similar to this:

{
"complete":0,
"formText":"<div class=\"error\">...<\/div>",
"returningNumber":12345
}

The json object is encoded using PHP's json_encode() function. In the event that the form has errors in it (empty fields, invalid inputs) the formText variable carries the entire html of the form to the front end and is then inserted in place of the current form.

The problem is that, from what I can tell, the Form Plugin does not allow HTML to be carried inside of a JSON object. I will only fire the success function when the data variable does not carry any HTML in it.

Is there any way around this? Am I not escaping something properly? Any info on this problem would be appreciated. Thanks in advance.

emachine
  • 1,135
  • 4
  • 17
  • 25

1 Answers1

1

You could encode your HTML part using htmlentities() PHP function, and then you can decode it like described in this question.

Community
  • 1
  • 1
Sylvain
  • 3,823
  • 1
  • 27
  • 32
  • Your answer did what i wanted it to do but for some reason it's still not being accepted as a valid response. I'll explore further. Thanks for the link! – emachine May 10 '11 at 14:33