Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Submitting URL encoded array of structured arguments. #89

Open
reygoch opened this issue May 27, 2018 · 1 comment
Open

Submitting URL encoded array of structured arguments. #89

reygoch opened this issue May 27, 2018 · 1 comment

Comments

@reygoch
Copy link

reygoch commented May 27, 2018

This might be slightly related to #62.

Let's say that I have these data types:

data Something = Something
    { field01 :: Text
    , field02 :: Text
    }

data StepInstruction = StepInstruction
    { id :: Int
    , order :: Int
    , description :: Text
    }

data Recipe = Recipe
    { id :: Int
    , name :: Text
    , something :: Something
    , instructions :: [StepInstruction]
    }

In PHP I could easily submit a form with such data type and get it back in the form of a nested array. Convention for submitting Recipe is as follows:

?id=0
&name=Recipe01

&instructions[0][id]=0
&instructions[0][order]=1
&instructions[0][description]=somedescription

&instructions[1][id]=1
&instructions[1][order]=2
&instructions[1][description]=someotherdescription

Currently Query flat and I'd have to do additional parsing on the argument names to get an array of structured arguments.

I'm not sure if this is a standard, but I've also seen the same convention in C#/MVC so I think it would be a good idea to support such feature, because I might want to add repeating "sub forms" to my main form that should be contained in array, and currently there is no good way to do that from what I can see.

Here is also an example of a form that might submit such query:

<form>
    <input type="hidden" name="id">
    <input type="text" name="name">

    <input type="text" name="something[field01]">
    <input type="text" name="something[field02]">

    <div>
        <input type="hidden" name="instructions[0][id]">
        <input type="number" name="instructions[0][order]">
        <input type="text" name="instructions[0][description]">
    </div>

    <div>
        <input type="hidden" name="instructions[1][id]">
        <input type="number" name="instructions[1][order]">
        <input type="text" name="instructions[1][description]">
    </div>

    <div>
        <input type="hidden" name="instructions[2][id]">
        <input type="number" name="instructions[2][order]">
        <input type="text" name="instructions[2][description]">
    </div>
</form>

Maybe QueryItem should look something like this:

data QueryItem
    = PlainValue ByteString
    | QueryItemList [QueryItem]
    | QueryItem (ByteString, Maybe QueryItem)
@aristidb
Copy link
Owner

Similar to what I said in #62, I am not in favor of changing the existing functions because that would break compatibility and also because this is not the most common way of using form inputs, I think.

However, if you want to make a new function that allows rendering/parsing nested data like that, you could send a pull request with new functions and types and if it looks good, it could be merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants