Create Json Form

How I can create form with this format with repeat structure ?

repeat
<form enctype='application/json'>
  <input name='attributes[0][val1]' value='test1'>
   <input name='attributes[1][val2]' value='test2'>
</form>

Something like this should work:

dmx-bind:name="attributes[{{$index}}][val{{$index}}]"

Although, since I don’t know what the context is here, so not sure if this is the correct solution.

Thanks, for your help.

How can I get this value on the server side to format json ?

All data on server side is treated as JSON.
I have seen multiple posts from you around this, and it all seems quite confusing.

With the above name binding, you should get a JSON in $_POST.
Just add a set value step on your SA with the values as {{$_POST}} and check the output shown in network tab.

The form generate this payload :

1. {connection_id: "307d3028-fd11-4be7-b716-9afd416486e8",…}

  1. attributes[0][test1]: "test-value"
  2. attributes[1][test2]: "test-value"

In the server connect side I need transform to put in input data in API action:

{
"@type": "issue-credential/1.0/credential-preview",
"attributes": [
{
"name": "test1",
"value": "test-value"
},
{
"name": "test1",
"value": "test-value"
}
]}

How do I get the values?

Here’s how I would do it:

<input type="hidden" dmx-bind:name="attributes[{{$index}}][name]" value="test1">
<input type="text" dmx-bind:name="attributes[{{$index}}][value]" value="test-value">

The value parts will be dynamic values from your repeat.

1 Like

How I can create repeat structure in server side to get values from form to set value to data ?

attributes is an array so you can use it in repeat step.
But why would you need that?
You can just bind the whole thing as is where you want this JSON. {{$_POST.attributes}}

In the server side $_POST.attributes is undefined.

My html form is :

Print $_POST variable to check what the value is on server side.