- Home /
How to use WWWForm to post multi-valued data?
You know how you can have radio buttons or checkboxes or other multi-select fields on an HTML form? I need to translate that into a WWW request from within my app, figuring WWWForm would be the thing to use. Simple enough with simple single-value fields. What's the syntax for constructing a multi-value field?
In other words, if the HTML were like this:
<form action="buy_snacks.php" method="post">
<select multiple name="snacks[ ]">
<option value="coke">CocaCola</option>
<option value="popcorn">Popcorn</option>
<option value="peanuts">Peanuts</option>
</select>
</form>
and the PHP were like this:
<?php
$snacks = $_POST['snacks'];
// Note that $snacks will be an array.
foreach ($snacks as $s) {
echo "$s<br />";
}
?>
What's the missing intermediate step here, the actual format of the data, that I'd use with the WWWForm object. Essentially, how do I convert that HTML to a Unity script, indicating my selections? (Or is there a better way?)
Answer by DaveA · Jan 28, 2011 at 02:07 AM
Why yes, quite simple, eg:
form.AddField ("snacks[]", "peanuts");
form.AddField ("snacks[]", "popcorn");
Hi, It works fine for me, but... do you know the size limit? Thanks.
There is no hard size limit. The post-data can be almost as long as you want. HTTP itself doesn't have a limit, but certain HTTP servers / server configurations will implement one for security. There's no general limit, so check your server config.
Your answer
![](https://koobas.hobune.stream/wayback/20220613101454im_/https://answers.unity.com/themes/thub/images/avi.jpg)