Render and submit form fields dynamically

Hi guys, let me explain my requirement. It’s easy to understand but I have no idea how to accomplish it on Yii:

Problem:

I need to render a view which must have several form fields which should be displayed according to a JSON input which may have multiple field definitions.

Sample JSON input:




{

  "id": "task1",

  "name": "complete vacation request",

  "author": "richard",

  "fields": {

    "field_1": {

      "name": "first name",

      "type": "text",

      "value": "default value",

      "required": true

    },

    "field_2": {

      "name": "married",

      "type": "checkbox",

      "checked": true,

      "required": true

    },

    "field_3": {

      "name": "age",

      "type": "number",

      "required": true

    }

  }

}



So, based on this JSON data, I must render a form with fields described by field_1, field_2 and field_3, as seen on attached wireframe:

5961

wireframe.png

And, when the the form is submitted, I must be able to retrieve all the submitted field values and continue some business logic with them.

What would be the best approach to accomplish this based on your experience. Have someone done this before?

I’m using Yii 2.0.

Thanks.

It’s a job for the form builder. Unfortunately, it’s scheduled for v2.1…

See https://github.com/yiisoft/yii2/issues/59

Thanks Ben!