3 ms·
Well, the safe way would be to mirror the current form spec and treat everything as arrays of strings by default. <form enctype='application/json'> <
by richdougherty 12y ago
Well, the safe way would be to mirror the current form spec and treat everything as arrays of strings by default.
<form enctype='application/json'>
<input type='text' name='fruit' value='apple'>
<input type='number' name='bottle-on-wall' value='1'>
<input type='number' name='bottle-on-wall' value='2'>
<input type='number' name='bottle-on-wall' value='3'>
</form>
{
"fruit": ["apple"],
"bottle-on-wall": ["1", "2", "3"]
}
Then add attributes to explicitly give the structure. Since this is a browser spec we can add attributes. Here's the same form but with some attributes giving the explicit encoding.
<form enctype='application/json'>
<input type='text' name='fruit' value='apple' enc='string'>
<input type='number' name='bottle-on-wall' value='1' enc='array/number'>
<input type='number' name='bottle-on-wall' value='2' enc='array/number'>
<input type='number' name='bottle-on-wall' value='3' enc='array/number'>
</form>
{
"fruit": "apple",
"bottle-on-wall": [1, 2, 3]
}
Dynamically varying JSON structures by form names and number of form elements is definitely going to be a source of bugs and security problems.