Halp! (Debugging)

StDoodle

Minion
For some reason, the following script always ends up with a hidden field with the name "mode" and value "LIST" even though, as far as I can tell, it should have a different value on other pages. Anyone with time to look through and tell me what idiotic mistake I've made would be greatly appreciated!

File in question: View attachment relay_CustomDaily.ash

(Note: requires htmlform.ash)

Edit: after further digging, the parameters passed to htmlform.ash's write_hidden() are changed somewhere inside the function. Basically, if your use a hidden field on multiple pages following each other, with the same field name, the value will always stay what it was on the first page write. Is this intended? (I've been a bit out of it lately, so I honestly don't know.)
 
Last edited:

jasonharper

Developer
ALL of the write_X() functions in htmlform use their value parameter on the first page load only. Afterwards they maintain the same value, as modified by any user interaction (which of course doesn't apply to a hidden field).

For what you're trying to do, I think you'd be better off writing a <input type=hidden> field yourself.
 

StDoodle

Minion
Ok, I figured that. I just had a gross misinterpretation of how certain things were done, and it kind of... compounded. ;)

For reference, I think I've "solved" this by rewriting how I handle button checking. Now, every single button I might create is checked in one handy-dandy place, which allows me to "remember" which sub-page I was on last. It's kind of a PITA due to all of the dynamically-created buttons I have, but not too bad; they simply have a unique name format, such that I can check them by combining a foreach loop through fields & index_of(). All of the "static" buttons are checked right before this.
 

StDoodle

Minion
New problem! I was under the impression that validator functions would prevent anything from happening when a button was clicked if any of them failed (ie no actual page submit would happen). Apparently, this isn't what happens, at least in my script with the custom validator functions I'm using. I even changed one out for the built-in nonemptyvalidator function (as I haven't customized mine beyond it yet, anyway), and still... nothing. I'm very confused...

Apparently, it's the order I'm confused on... as in, the button still submits the "first" time, but won't submit again unless the errors are fixed? Huh... I don't get it... Also, test_button() seems to me to be returning true when it shouldn't, but this is likely related to the above... I'm so confused...

View attachment relay_CustomDaily.ash
 
Last edited:

jasonharper

Developer
Clicking a button always submits the page - there's no other way for your script to be invoked again, in order for it to do the field validation.

A validation failure causes an error message to be written as part of the field, and the 'success' flag set to false. That's what test_button() tests; its return value is only meaningful if called after all of the validated fields have already been written.
 

StDoodle

Minion
Ah. That's kinda what I was figuring. I can see how that would be useful for simpler scripts, but my rather-convoluted multi-page thingy needs... "special" handling. Looks like the function that saves the data has to re-validate as well. No bigee.

One thing that WAS difficult to surmount; when saving (via file_to_map()) and restoring a list of records, some of the fields of which are records themselves, the secondary records don't get loaded properly if there are multiple fields in the secondary record of the same type, and one of them is null. (For reference, my master record has an array of sub-records that consist of two strings; the two strings aren't loading properly.) The only solution I could come up with was to avoid saving "" and instead swap out " ".
 
Top