-
-
Notifications
You must be signed in to change notification settings - Fork 681
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
Follow standard convention for Arrays #33
Comments
I'm not sure if I want this to be part of formdiable yet. I can see how it's nice, but at the same time it feels like sugar that can easily build on top of formidable. Let me know why you think it's important. |
Perhaps my understanding is incorrect (I'm using express, not formidable directly, so correct me if I'm mistaken), but formidable can't currently accept uploads from multiple input fields So either using the common convention
Or not
I can't get access to The HTML spec treats all form fields as Arrays. However, that's the same ugly way that xml does it. I agree that we should not encourage that mistake -- especially since web frameworks have traditionally used the Although it may not be the best solution, but it's what end-developers are accustomed to. That said, I would be okay with any solution to the bug
The issue is that when I use a multiple file input form, I should be able to get at all the files. |
yeah I dont personally care what the solution is but this is pretty important, |
The API supports that. You just need to listen for the |
connect-form is just a really thin layer around formidable, I think it is the final callback wit the field hash that ends up being "invalid" with multiples |
The callback is meant as a simplified API which doesn't handle multiple fields with the same name. But I guess connect-form is not meant to "emit" individual file events anyway? --fg |
Here's a paired Client / Server upload test case: And the reference HTTP POST: |
So which of the two should change? Express or Formidable? I would really appreciate formidable handling it appropriately since I won't always be using express when I handle uploads, but I would pretty much always like to use formidable when I handle uploads. I think that the change will benefit more projects in general if it happens in the formidable layer. |
you can still use formidable directly.. connect-form is just a convenience middleware |
This select tab with multiple fields problem is definitely a bug. I use formidable without express or connect and it is impossible for me to accept same-named fields. I will try the patch provided a few months ago but I'd prefer to use unpatched formidable. I also vote for adding "[]" to the name as a de-facto standard. |
No, you are misunderstanding the current API.
That's not true. You can listen to the This doesn't mean that I won't change the API, apparently most people prefer magic over predictable outcomes, but please don't spread FUD. |
I'm sorry, I didn't know about the event solution. i missed that in the docs. One would like to just have the fields in an obj, not go to the trouble of setting event handlers. It isn't a bug, just a pretty big inconvienence. |
For clarity (And I'm aware this is an old thread), you can add and event listen for the "file" event, emitted by formidable, to capture every file rather than use the callback with the formidable.parse() method:
|
I'm wanting to use formidable with normal arrays of fields (not file fields), so I'm working on a fork now, I found the perfect spot for the code to go. I'll do a pull request in a second when I'm done. It will let you do things like:
And then in the fields parameter of the cb we'll get I'll post a comment once I've finished and made the pull request |
I've submitted the pull request: #77 |
@felixge, any news on this? I agree with others here that foo[] should return an array... |
@shanebo No news yet, but I'll keep you posted. I'm getting to this soon I think |
@felixge thank you! |
I am not exactly, sure, but I think that this is adding to the problems: tj/node-querystring#30 |
@atheken I don't think this ever landed. |
@felixge, excuse me for bringing back this old issue, but I think you should take into consideration the following aspects: (1) Having a form submission (without file fields) yield different results when the form is submitted with different enctype is a big no-no. (2) The argument for simplicity is weak in this case. If you would return an array only for multi-valued fields, the code for processing forms without multi-valued fields (i.e., the kind of forms that are supported right now) would be exactly the same as now. (3) The way multi-valued fields are handled right now is also bad for files. If Joe Attacker submits a form with many files having the same field name, the callback only sees the last one, and is unaware of the others. Repeat such submission many times, and the disk could fill up, opening a vector for a DoS attack. The fix is trivial, and I have already implemented it on my system. The reason I am taking the time to discuss this is that I find formidable to be a very nice piece of work, and this is a simple fix that would make many a programmer's life easier, avoiding the need to reimplement this stuff. Everyone would benefit from having a single form processing module in node that handles all cases well. |
if somebody volunteers to make the change and deal with any problems / tickets that result from it, I'm happy to give him commit access |
@felixge, thank you very much for your interest. I will happily deal with any tickets resulting from this change -- I am pretty sure there will be few (if any), since the change is trivial and does not break anything on forms without multiple-valued fields. I have never used git before, but here is a tested patch (to apply with -p1 inside the formidable directory):
If you prefer that I commit the change myself, please let me know and I will learn how to do it. |
@rcprior thanks. The patch looks good. Additionally this change will require:
Given that you're new to git I'll not give you commit access right away to avoid accidents : ). So could you please go ahead and send your change as a pull request? It will require "forking" the repo via the fork button, committing / pushing the change into your forked repo, and then creating the pull request. These guides may help: Thanks |
@felixge, I documented the new behavior (and also fixed some issues in Readme.md) and updated test/legacy/simple/test-incoming-form.js to reflect the new behavior (since it was testing for the behavior of dropping all values of a name but the last), but now I'm stuck with testing errors that are unrelated to my changes (they also occur on a fresh clone of your code):
|
@rcprior not sure what the problem is, the master tests seem ok on node 0.8, 0.10 and 0.11 on Linux. https://travis-ci.org/felixge/node-formidable |
Why don't make a joint effort to get this trivial code merged, 3 years and still open? |
I don't know if this issue is solved or not.
That's all. I hope this helps others. |
@Ali-Azmoud Thanks..... |
We now handle all those scenarios
attribute multiple + array merges into one array. |
@GrosSacASac link to commit? ie.) client: <input type="text" name="people[0]['firstName']" value="Jerry">
<input type="text" name="people[0]['middleName']" value="T">
<input type="text" name="people[0]['lastName']" value="Mouse">
<input type="text" name="people[1]['firstName']" value="Tom">
<input type="text" name="people[1]['middleName']" value="R">
<input type="text" name="people[1]['lastName']" value="Cat"> server (JSON output): {
"people": [
{
"firstName": "Jerry",
"middleName": "T",
"lastName": "Mouse"
},
{
"firstName": "Tom",
"middleName": "R",
"lastName": "Cat"
}
]
} note: you get this functionality built-in now, in express.js v4.16+, see express.urlencoded |
please make a new issue for extra functionality, so we can keep track of it, |
Yup. It's not working with multidimensional arrays. We should introduce querystring parsing for this. New issue please :) |
@lmj0011 & others. Please try We also support easy adding of custom parsers, so it's welcome for more advanced querystring parsing and etc stuff. /cc @s4kh may be interested. |
Why is this issue closed? Formidable still does not parse array fields correctly. It gives "[object Object]" |
We chose to not do it. form inputs with the same name, (regaredless if they have []) will be in the same array |
According to common convention (i.e. php, python, ruby) named fields ending with square brackets
[]
should be treated as arrays.This example HTTP POST should produce a parsed object like the one shown here below:
Shorter snippet from link above:
Parsed Object:
The text was updated successfully, but these errors were encountered: