Form of...HTML!

xKiv

Active member
If I put 1+2 in a textarea with GET method, my firefox sends it as 1%2B2 in the URL ...
That's then decoded *twice* in RuntimeLibrary.form_fields():
Code:
// Something's messed up here - form values are
// double-URLencoded!
String decoded = URLDecoder.decode( pieces[ 1 ], "UTF-8" );
decoded = URLDecoder.decode( decoded, "UTF-8" );
Presumably, the first one converts %2B into a + (which is the same in UTF-8 as in ASCII), the second on converts the + into a space.
Maybe your
And a recent change that I submitted should make KoLmafia NOT URLencode browser-submitted URLs again.
fixed the issue where form values were double-encoded?

ETA: ninjad'
 

Veracity

Developer
Staff member
I was referring to Revision 8767 which says:
Add a three-argument form of visit_url:
visit_url( string location, boolean usePostMethod, boolean encoded );
The third argument indicates whether the &-separated fields in the location are already url_encoded. If not, KoLmafia will split out the fields at & boundaries and encode them, as before.
You probably won't need to use this unless your field values contain a &.
and Revision 8785, which says:
When setting up relay request for use by a relay override script, clone the URL correctly: allow for requests submitted by either GET or POST, and recognize that the arguments are already URL encoded.
... both of which messed with URLencoding as see by relay scripts. Messed with correctly, I think. :)
 

StDoodle

Minion
form_fields() currently assumes that all fields are double-URLencoded; that being no longer true would certainly explain the problem. I'll look into it...

Thanks! :)

Also, a htmlform usage note: passing fields["copypasta"] as the initial value parameter to write_textarea() is pointless, that parameter is only used on the first pageload of your script, at which time there are no fields.

Well, since the initial pageload should be blank, it's fine; after hitting the "Load" button, if the same code is ran again... which it is in my case (with some additions that make things clearer in the full code)... then whatever you put in the textarea stays there. Other than, you know, the encoding issue. ;)
 

StDoodle

Minion
Question: shouldn't the closing tag of </label> be part of write_select() rather than finish_select(), so that it's after just the label text, not the entire selection? (I'm honestly asking, as I'm far from an HTML expert.)
 

jasonharper

Developer
If the <label> tag encloses only the label, it requires a 'for=' attribute to associate it with the actual form control it labels. If the form control is inside the <label> tag, then the association is automatic.
 

icon315

Member
when using write_button() like this:
PHP:
    itm = write_field("", "itemnum", "Item Number: ").to_int();
            write_button("submiting", "Add");
it seems that as soon as the page loads, it submits and returns 0. Is there a way to make it so that it doesn't submit unless the button is pressed?
 

slyz

Developer
Instead of doing
PHP:
itm = write_field("", "itemnum", "Item Number: ").to_int();
directly, why not do:
PHP:
write_field("", "itemnum", "Item Number: ");
if( fields contains "itemnum" ) itm = fields["itemnum"].to_int();
?

If fields contains "itemnum", then you know the submit button has been pressed, otherwise you can deal with the situation in another way.
 

icon315

Member
thanks

EDIT:
i tried using this, but at no avail. it just submited with a blank. so it came out as:
Code:
...
3	4548
4
it also adds a blank line
 
Last edited:

jasonharper

Developer
You have to either check the return value of write_button(), or use test_button() to determine that the button was actually clicked.

slyz' advice is simply wrong; the presence of a field name in fields[] does not prove that a successful page submit actually took place.
 

icon315

Member
ok i did this
PHP:
     string [int] my_items;
    file_to_map( "My_Items.txt" , my_items);

    attr("size=4 maxlength=4");
    itm = write_field("", "itemnum", "Item Number: ").to_int();
            write_button("submit", "Add");
			


		if (test_button(itm) != false){
        string [int] my_item;
        ........
}

i think it should work, i'll try after Rollover
 

slyz

Developer
I use the advice I posted on checkboxes, I forgot about test_button() and validators and such. Sorry.
 

icon315

Member
test_button is returning false even though i put 3661.

PHP:
print(itm);
print(test_button(itm));
Code:
3661
false
 

Banana Lord

Member
Random trivia of which you may or may not be aware: Chrome and FireFox require a value for write_field()'s label (even if it's just a space) before they will display the field, while Safari does not.

Is there any way to work with aggregate references? I'd like to use write_textarea() to display and edit a list of effects contained in a data file (after striping out the trailing <tab> required by map_to_file()). Perhaps I'm going about this the wrong way, but I can't find a way of doing it.
 

jasonharper

Developer
I find it extremely hard to believe that any browser would refuse to show unlabeled fields; there must be something else going wrong. Minimal example, please.

A textarea displays and edits text... you'd need to create a string version of your list of effects yourself, and then parse it back into a list on page submission. An alternative would be to have a bunch of checkboxes, one for each relevant effect, with an initial value that's true if the effect is contained in your list.
 

heeheehee

Developer
Staff member
Force your user to use JSON! :D (essentially:
Code:
"map":
{key: 11,
 "other key": "hello"}
array:
[11, 23, 37, 42]
If you do anything with JS, you can at least use JSON.parse(). Not immediately sure how you can translate that back into ASH. Although if it's one of the fields that's submitted, it's easy enough to write a JSON parser.
 

Veracity

Developer
Staff member
KoLmafia has a JSON parser built in. With some effort, we could make a set of ASH functions to interface with it.
 
Top