2

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

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Sorry what do you mean by attach it to BaseForm, you mean rewrite the symfony file?
No, the Symfony sfForm inheritance chain contains a BaseForm class that is yours to add methods to.
He means BaseForm in lib/form/BaseForm.class.php.
but every widget has its own render, how do you add JsonRender without touching the Widget classes?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.