2

Firstly, apologies if I use some incorrect terminology - I'm still very much a Drupal newbie!

I'm creating a band website using Drupal 6 with CCK, Views, Date, Calendar, Link, Location and GMap. It has two content types of concern here - Gig and Venue.

The "Venue" content type has a Location field, which stores all the address information. It also has some other fields, for example "Venue Website" (field_venue_website).

I want an autocomplete field on the "Create Gig" page to look up an existing venue from the "Venue" content type and display the venues in an autocomplete drop-down list in the following format:

[Location name], [City], [Country]

However, I want to extract more information to be available on the Gig page, preferably like this:

[Location name] <-- preferably as a link to the venue's page [Street] [Additional] [City] [State/Province] [Postal code] [Country] [Venue Website] <-- remember this is a separate field, not from the location field.

I have partially reached my goal, by doing the following:

  • Created a "Venue" field (field_gig_venue) of type Node reference.
  • Set up the field as follows:
    • Autocomplete matching: Contains
    • Size of textfield: 100
    • Required: Off (may change this later)
    • Number of values: 1
    • View used to select the nodes: venue_search
  • Created a View (venue_search) with the following settings:
    • Row style: Fields
    • Inline fields:
    • Location: Name
    • Location: City
    • Location: Country
    • Separator: ,
    • Hide empty fields: Yes
    • Relationships:
    • Content: Venue
    • Fields:
    • Location: Name
    • Location: City
    • Location: Country
    • Node: Title (Exclude from display: Yes)
    • Filters:
    • Node: Type = Venue

This results in the autocomplete drop-down list displaying as I required. When submitted, the result is [Location name] as a link to the Venue's page.

However, I find that the only part of the venue recognised by the autocomplete is [Location name]. For example, if I have two venues as follows:

Kentish Town Forum, London, UK

Tunbridge Wells Forum, Kent, UK

When I start typing "forum", I'll get a drop-down suggestion list that looks like the above. Great! However, if I type "UK" or "London", I get nothing.

If it helps, here is the query generated when I preview the View:

SELECT node.nid AS nid,
   location.name AS location_name,
   location.city AS location_city,
   location.country AS location_country,
   node.title AS node_title
 FROM drupal_node node 
 LEFT JOIN drupal_content_type_gig node_data_field_gig_venue ON node.vid = node_data_field_gig_venue.vid
 LEFT JOIN drupal_node node_node_data_field_gig_venue ON node_data_field_gig_venue.field_gig_venue_nid = node_node_data_field_gig_venue.nid
 LEFT JOIN drupal_location_instance location_instance ON node.vid = location_instance.vid
 LEFT JOIN drupal_location location ON location_instance.lid = location.lid
 WHERE node.type in ('venue')

Here are my questions:

  1. How do it get it so that the autocomplete will work for the City or Country, too?
  2. What is the best way to get the output that I require on the final page (i.e. an address block)? I assume that I can add the other relevant fields and exclude them from display in the View, and they'll be available to use. How should I best use them, though? A single field with the data pre-formatted? A field for each value?
  3. How do I then get the data collected from the View into the field(s)?

Any help would be greatly appreciated! Thanks in advance!

[EDIT]

As mentioned below, I have discovered that what is happening is this:

The autocomplete field takes the text entered and looks to see what node titles in the "Venue" content type match this text. It then displays the results using my View to format them. Here is a picture to illustrate:

http://img215.imageshack.us/img215/3539/autocomplete.jpg

Why is it ignoring my view when checking the entered text, instead checking against node titles?

0

I have an alternative for your 1. question. You could use the module Automatic Nodetitles to automatically create a title for venues in the form [Location name], [City], [Country] from CCK fields in your content type. This means you would have to use an additional textfield for the location name, and the title would be automatically created to combine the three fields.

This solution would mean that the city and country would be visible everywhere you use the venue content type title, you'll have to decide if that fits with what you need.

  • I don't know whether that would be an acceptable solution, as some venues have multiple names - for example, what is often referred to as the Kentish Town Forum is officially the HMV Forum, but people would usually either call it the Forum or Kentish Town Forum. As it stands, I'm using the titles to reflect this alternative. However, i;ll have a look at your suggestion and see whether it would be acceptable. – eggplant_casserole Apr 15 '11 at 19:31
  • I've had a look at it. Again, it comes down to the same problem - I don't know what code to use to get [Location name], [City], [Country] from the Location field. Can you advise? – eggplant_casserole Apr 15 '11 at 23:50
  • @eggplant You shouldn't need any php code. Make sure you have the Token module installed and just use the relevant tokens. Each CCK field should be accessible as an identically-named token, there is usually an expandable reference of all available tokens present at any place you can input tokens. – Mad Scientist Apr 16 '11 at 13:30
  • Thanks! Again, I'm a COMPLETE Drupal novice and wasn't aware of the Token module, so thanks for bringing it to my attention. I didn't say PHP code specifically, but I guess this was an example of me using the wrong terminology and I probably meant pattern. Incidentally, it is [location-name_N]. However, I don't really want to use this method, and would rather work out why it's ignoring my View when it comes to the autocomplete text and what I type in the autocomplete field is only referenced against the node title (as mentioned above). – eggplant_casserole Apr 17 '11 at 1:50
  • I have tried this method, and it works! The autocomplete is hard-coded to look up via the node title. Altering this seems too complex, so I'll go with your solution. Thanks! – eggplant_casserole Apr 18 '11 at 0:59
0
  1. You can create a computed field in Venue with the content of the fields you want and use that field.

  2. & 3. Once you have the node reference you can show whatever fields you want using a template for the gig. Alternatively you could use a view.

  • Thanks for your reply. It looks like I'm finally going in the right direction, now! – eggplant_casserole Apr 12 '11 at 18:33
  • Hmm, as I'm new to this site, I wasn't aware of the auto submit on Enter feature... or the 5 minute edit rule! Would you be able to elaborate on a couple of things? - When you say "in Venue", do you mean the content type or the field (in Gig)? Sorry, that's my fault! - What is a computed field exactly? A Google suggests that Computed Field is a module - should I install that? - Do I then ignore my View and use this computed field, or do they work together? - How exactly do I create a computed field to achieve what I require? Sorry for my extreme noobishness on this! – eggplant_casserole Apr 12 '11 at 18:41
  • It's an additional field in the Venue content type. And yes, you have to install that modeule. It will allow you to put all the data you want in one single field. Then you can use your view to search on that field. – sharpbites Apr 13 '11 at 14:05
  • Thanks! That makes sense. Unfortunately, I still don't know how to reference the Location fields in PHP - I can't find this information anywhere! What code do I need for the computed field to get what Views calls Location: Name, Location: City and Location: Country? – eggplant_casserole Apr 13 '11 at 14:41
  • Use the devel module to inspect that (I use dsm to print that out). It will be something along the lines of $node->locations[0]['name'] . ' ' . $node->locations[0]['city'] . ' ' . $node->locations[0]['country']; – sharpbites Apr 13 '11 at 21:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.