Go through inputs with the same name and get all values

Asked

Viewed 555 times

3

I have a web application in which I pass by input hidden a dynamic number of values across from a form to a action delphi.

In the action, I wanted to know a way to get all the values with the same name.

When there’s only one value, i use request.ContentFields.Values['numero']

I am passing the form inputs as follows:

<input type="hidden" name="numero[]" value="123" />
<input type="hidden" name="numero[]" value="456" />
<input type="hidden" name="numero[]" value="789" />

But how do I get everyone inside the action?

  • The conventional way returns only the contents of the first input.
  • I tried to create a dynamic array and pass it to it, but it didn’t work.
  • Is using intraweb?

  • not Tiago. Here we do by playing html inside a Replay.content

  • okay, interesting. If you know a link on the web about an application similar to what you do I would be happy to see it, because I would like to know it. Grateful!

  • But by the way, the properties name are at the value number[]. you’re playing an index on those names, right? So that you stay.. numero[0], numero[1], numero[2] and then receive by a vector..

  • James. What I wanted was to bake everyone with the same name and go through all of these in the action and take the values. Since I’m not being able to figure out how to do this in Delhi 7, I’m moving on to this solution you asked. I will pass several inputs with different Names. So I will be able to take the other side quietly.

1 answer

1

Come on, I don’t know how this is what you’re doing for Delphi, so I’m going to use an approach we have on C#.

If you have something like that:

<input type="hidden" name="numero[0]" value="123" />
<input type="hidden" name="numero[1]" value="456" />
<input type="hidden" name="numero[2]" value="789" />

Then you’d have something more or less like this in Delhi:

type
  TIntegerArray: Array of Integer;

procedure TMinhaClass.MinhaAction(numero: TIntegerArray);
var
  I: integer;
begin
  // podendo então:
  for I := 0 to High(numero) do
  begin
     // fazer o que deseja com "numero[I]".
  end;
end;

That answer is entirely based on speculation. Another point is that the fields must always have an order, no breaks, because something like:

numero[0]
numero[1]
numero[3]

Something like this you would receive only the values with index 0 and 1 in your action, the field with index 3 would not receive because of the break. Confirm that as well.

  • I understood your approach. But what I have are with same Names. I’m already giving up and going through with different Names even. So it’s simple to take.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.