I have a cck module that currently does this
- User enters and saves username for a third party website on the module settings page
- User adds/edits a node
- When user gets the add/edit form, their username is fetched from settings, and is used for an api call which fetches some data, this data fills a select on the form.
- User selects something from the data filled select, and on save the node is created with custom content.
This works, but I'd like for it to be able to do this
- User adds/edits a node, form is shown, and some default data populates the select referenced above
- User enters their username in a textfield on the form, clicks a button which fires an api call, and the select is filled with the data retrieved from the api call
- User selects something from the data filled select, and on save the node is created with custom content.
edit
I'm going to try to do this with javascript instead of having ahah take care of things for me. So, when the button is clicked, the api call is still fired, but now the change of the select elements is entirely done with ajax and dom manipulation. However, when this form is submitted, I get this friendly error.
An illegal choice has been detected. Please contact the site administrator.
and from what I understand, this is caused by the form_state being different from what's stored in the form (my modified select list).
I have a few ideas of how to circumvent this error, but I'd like to know if anyone's got a different idea of how to do it.
I've been playing around with AHAH to get this working, but it's been difficult as I can't find any examples similar to what I'm attempting to do, or any explanations of how to use AHAH with CCK. I have the AHAH callback set up so in the hook_process callback of hook_elements, and the callback is being executed, but I think there's a mismatch in what's in the cached form_state and what's being displayed on the screen because when saving/previewing the node, there isn't anything displayed other than the menu and navigation. I've gotten the correct info to show up on the webform, but on submit, it fails.
I'm also a little lost as to the correct way to make AHAH work with CCK and exactly what I'm supposed to return and do. (return a regenerated part of the form? what do I cache? etc.)
Thus, does anyone have a suggestion of steps to get the ahah callback working, know of examples of ahah working with webservices and/or cck, or have alternate ideas?
I hope that's clear, and thanks for your insight!