Reputation: 109
I am looking for a way to automate a form output to json format instead of html. I am using JQuery dform http://plugins.jquery.com/project/dform to create dynamic forms.
Sample output:
{ "type" : "p", "html" : "You must login" }, { "name" : "username", "id" : "txt-username", "caption" : "Username", "type" : "text", "placeholder" : "E.g. [email protected]" }, { "name" : "password", "caption" : "Password", "type" : "password" }, { "type" : "submit", "value" : "Login" }
Please help
Upvotes: 2
Views: 1239
Reputation: 10403
Create a renderJSON
method and attach it to BaseForm
. The method would iterate through the the sfFormFields
and build an array that you could then pass to json_encode
.
An ideal solution would be to inject your own class into the sfWidgetForm
inheritance chain with a renderJSON
method so that individual widgets can control their JSON format. Unfortunately, Symfony makes this very difficult to do.
Upvotes: 3