Hey,
For a Drupal 7 module I'm working on, I'm trying to figure a way for my autocomplete_path function for a textfield to return additional information back to the hook_form function it was called from.
If including the additional info in the return (which I have a strong feeling) is not possible, is there a way to define variables in a scope to make this work decently for a per user per form basis?
The reason I want to do this is that I'm getting the auto complete info via querying another site for musical information and returning "artist - song" for the textfield but would like the function to also return a song ID (hidden form the user) that I could use back in the form show additional information about the song (e.g. album image.)
Any help is appreciated.
Thanks!
-mr
Comments
There are two ways I can
There are two ways I can think to do this:
1) Include the ID in the text.
2) On submit, query the external site once more using the data that you have, and get the ID that way.
Thanks for the quick response.
Thanks for the quick response. I have considered these but have realized the following problems with them:
1) The id is a 12 digit number and I can't bring myself to put it in the text.
2) The external site I'm querying may not return the correct information on a second query based off of the returned text for the first as it takes into account other factors in addition to the actual query such as popularity. Ideally I would love to know exactly what the user selected the first time instead of hoping the second query returns it.
Thanks again for your response. I appreciate you trying to help me.
Ok, another way you can do it
Ok, another way you can do it is like this. When generating the array that is turned into the autocomplete values, you generally set the key and the value to the same:
Instead, you can split up the ID and the value. Something like this:
This way the key is the ID. The only problem with this method is that I believe it will insert the ID into the textfield when the user selects the text, rather than inserting the result. So it doesn't look the cleanest, but it will work.
If this is no good for you, then the only other solution really is building your own autocomplete I think.
Yeah.. Looks like I'll have
Yeah.. Looks like I'll have to pick my poison with this one.. Thanks again for trying to help.
I actually feel better knowing that there's no hidden option (4) that I couldn't find documented anywhere :)
work arround available?
I have the same question as MR. It one of the most default things to submit an ID to a hidden field on a autocomplete field. Is there any workarround available?
Read the whole thread.
Read the whole thread.
This is exactly what I am
@Jay Matwichuk
What you mentioned in comment #4019358 is exactly what I am trying to do, but I can't seem to get it to work correctly. When the user types in the autocomplete field, the suggestions include a user picture, the username, and the user's location. When one of the suggestions is selected, I would like just the username to be inserted into the textfield. I tried setting the key to the username in the way you suggested above, but it does not change what is inserted into the textfield.
Any ideas on how to do this?
Thanks!
Third party service to populate multiple CCK fields
1. Create a widget that is an autocomplete text field
2. Create menu for autocomplete.
3. Create a callback that queires the third party system and returns multiple options for the autocomplete text field
4. Extend the Drupal autocomplete server side code to process query.
5.Add js script to make Ajax query
6. Query the third party service again! Acquire all information and map each piece to each CCK field for the ajax call to the server to change the 'value' attribute of each text field.
Nice little tutorial!
Nice little tutorial!
many thanks
Nice tutorial, many thanks (and always good to see OL code ;))
Wow. Thanks.. That is an
Wow. Thanks.. That is an awesome tutorial.. You should add that to the Drupal Docs :)