I had some problems with write_check() and finally figured out what was happening. I spend some time getting my head wrapped around writing a Relay ASH script, and ended up doing things this way, since my script involves updating the amount of items in inventory:
- I build a map of certain inventory items and their quantities.
- I write the header.
- I test to see if certain buttons have been used, execute commands and update my item map so the rest of the script can decide what to show.
- I write the rest of the page accordingly.
I was trying to use check fields, but after hitting a button, the page would be be refreshed with all the checkboxes checked. What was happening was that, by testing for the presence of a field in the fields map, a key for that field was added with the default string value "". I modified write_check() in htmlform.ash, changing
PHP:
if (fields contains name )
to
PHP:
if (fields contains name && fields[name] != "")
as a workaround.
I would like to point people who will use my script to this thread so everyone can download the same htmlform.ash, so I guess my second best workaround (not involving modifying htmlform.ash) would be to remove the empty fields[name] value each time I check for a name that isn't in fields, by doing:
PHP:
if (fields contains name ) {...}
else remove fields[name];
I guess my questions are:
- Should I make a feature request, asking that checking for a key in a map doesn't add the key in said map?
- Is the htmlform.ash in this thread going to be updated/maintained, à la zlib, and can we direct relay script users to download it? Or would it be better to make an accompanying library for each separate script?