My site is the latest version of Drupal 6.xx; all modules are current.

I have a custom content type for a series of events promoted by my employer. One of the fields that is entered for each event is the address.

I want to display the address as a link to Google Maps, so in the body template I have this bit of code:

<?php
  if ($node->field_onebook_location[0]['view'] != NULL){
  $location = $node->field_onebook_location[0]['view'];
  $map = "<a href=http://maps.google.com/maps?saddr=&daddr=" . $location . ">" . $location . "</a>"; } ?>
  <div class="field-items">
      <div class="field-item"><?php echo '<br>' . $map ?></div>
</div>

If the location is something like "Barstow-Evans Center, 123 Main St, MyCity, MyState, MyZip", the clickable link is "Barstow-Evans Center, 123 Main St, MyCity, MyState, MyZip", but the link itself gets clipped after the first space, so the link ends up being:

"http://maps.google.com/maps?saddr=&daddr=Barstow-Evans " (there is a space at the end of the link)

I'm probably overlooking something really simple here. A nudge in the right direction would be greatly appreciated.

Comments

nevets’s picture

I believe you want

  $map = "<a href=http://maps.google.com/maps?saddr=&daddr=" . $location . ">" . $location . "</a>"; } ?>

to be

  $map = "<a href=http://maps.google.com/maps?saddr=&daddr=" . rawurlencode($location) . ">" . $location . "</a>"; } ?>
mpruitt’s picture

Nevets, you saved my bacon one more time!

Works great.