Would appreciate some help getting AHAH to work for me. I've been *mostly* successful, but I just can't seem to find appropriate examples online to move me forward (it seems everyone using AHAH does so to modify the appearance or content of a form... I'm using it a bit differently).

1) I have two blocks on a page... one displays a table (where I employ the 'table' and 'pager' themes), the other is a "filter" form to determine what to display in the table.
2) My first iteration works great....
a) User changes one-or-more filter settings, then hits "Submit".
b) Filter settings are stored in a database (or session data for an anonymous user). [considering packaging this as a module, it works nicely].
c) The page is reloaded (the default) and the table reconstructed using the stored filter settings.
3) Iteration two was to have the table update without requiring an explicit "Submit", say for example when a drop down value is changed.
a) After much digging and experimenting, everything seems to work... the table is regenerated properly... but...
b) The links generated for the table-sort headers and pager buttons are wrong.
1. They reference the path to the AHAH handler, not the page path. So "publications" is "publications/js" (in my case).
2. The query string is quite borked. Instead of "?page=1" (for the first pager button), I get "?page=1&" + all of the form data strung together, terminated with "&form_id=blah-blah".

So I'm thinking in the AHAH handler, the context is wrong for the table and pager themers to construct correct links. That I should be somehow resetting some 'destination' property and clearing all the form data? Or caching it, clearing it, constructing the HTML for the table (with proper destination and query), then restoring it?

This is a bit more complex than I'd hoped and help would be appreciated. I can post code if needed... and you can see it in action at www.authorcollector.com/publications. I've only hooked up the "Date" select control to AHAH at this point. You *do not* need to register to see the issue... anonymous users are supported in a demo mode.

1) To see things work, go to authorcollector.com/publications, set "Binding" to "Paperback" and select "Apply Filter". Table will change and headers/pager buttons have correctly-constructed links.
2) To make it fail, go to authorcollector.com/publications, set "Date" to "In the last year" (AHAH will just happen). Table will change and headers/pager buttons have incorrectly-constructed links.

Thanks,

Mark

Comments

markallenneil’s picture

Been winging my debugging to-date... but for this problem I resorted to instrumenting my code with file_put_contents('debug.log', print_r($an_array, true), FILE_APPEND);. Works.

So what I did...

1) In the AHAH handler I cached $_REQUEST and $_GET.
2) UNSET the form-specific parameters in $_REQUEST and set $_GET['q'] to the page I wanted ('publications', not 'publications/js').
3) Call the function which builds the table using the 'table' and 'pager' themes. The links are set correctly without the insertion of the form junk and to the correct path.
4) Restore $_REQUEST and $_GET from my cached values.
5) Return the JSON object.

So perhaps 10 lines of code... and it all works. Yet I feel so dirty now... seems like a hack.

Comments, anyone?

Mark