I am working on a web application written in delphi and am having trouble getting the values from an array of values. The form looks similar to this:
<form method="post">
<input type="hidden" name="keyword[]" value="1"/>
<input type="hidden" name="keyword[]" value="2"/>
<input type="hidden" name="keyword[]" value="3"/>
<input type="submit" value="submit"/>
</form>
If this were a single input with a unique name, I could pull the data using this:
var cKeyword : String ;
cKeyword := Request.ContentFields.Values['keyword'] ;
I’m looking for something like this:
var aKeywords : Array of String ;
aKeywords := Request.ContentFields.Values['keyword[]'] ;
In PHP you could just use $aKeywords = $_POST['keyword'], I’m hoping there’s a way to do this in delphi.
Thanks in advance for any help you can provide.
The
ContentFieldsproperty is just an ordinaryTStringsobject, so itsValuesproperty always returns astring. When an HTML form has multiple successful controls with the same name, they’re simply all returned, one after the next. That means theTStringsobject will have multiple entries with the sameNamesvalue. You’ll need to iterate over all the entries to find the ones with matching names.Here’s a function that might help.
Call it like this: