Hi,

I'd like the ability to force users to enter in a full/partial address on registration. I'm currently doing this using user profiles but I would prefer to use the location module as then I would also gain the ability to show user locations on a map using gmap.

Stella

Comments

lias’s picture

Component: Miscellaneous » User interface
Category: feature » support

The location can be added to the user profile during registration, enable it at admin/module settings/location.

I've enabled it but there doesn't seem to be any way of requiring the location fields to be filled out by the user. THis can be done when you create a new node and enable the locative features but I can't seem to find where to do this for the user's profile.

Any ideas?
Thanks!
lsabug

davea’s picture

No ideas! Sorry!

This bug has existed for awhile now. Here is the one for 4.7: http://drupal.org/node/119365

I am posting this bug so it doesn't get lost.

stormsweeper’s picture

Category: support » feature
Status: Active » Needs review
StatusFileSize
new13.63 KB

I needed similar functionality (as well as the form on account creation) so I hacked up some changes. Attached is a patch against version 1.80 of location.module.

  • New admin sub-page for the user location settings
  • optionally collect on account creation in addition to profile
  • fields shown and required may be changed
  • fieldset title, description, collapsibility, and weight may be changed
stormsweeper’s picture

StatusFileSize
new13.93 KB

The above is a patch against HEAD. Here's a patch against version 1.79.2.4 from the DRUPAL-5 branch.

davea’s picture

I have patched my dev system with this. It appears to work properly.

lias’s picture

Will this patch be rolled into the next update of the module?

davea’s picture

This patch works. However, the required fields for for the user regstration are not stored/retrieved properly. I have spent a few hours looking at this bug and I am still puzzled by ti. The way the new FormApi works has something to do with it but I am not sure what.

I am going to spend some more time on this bug with this patch.

davea’s picture

OK, here is what I have found:

admin/settings/location/user neither stores the settings for required fields correctly NOR does it retrieve them correctly.

Here is a sample of BAD DATA that is inserted in the variable table after setting the zip code to be required:

a:7:{i:1;i:1;i:0;i:1;s:6:"street";i:0;s:4:"city";i:0;s:8:"province";i:0;s:11:"postal_code";i:0;s:7:"country";i:0;}

Here is what should be stored/retrieved:

a:5:{s:6:"street";i:0;s:4:"city";i:0;s:8:"province";i:0;s:11:"postal_code";i:1;s:7:"country";i:0;}

I have NO idea why this is occuring. I saved the second value in the DB and user registration now shows the zip code to be required, which is the expected and desired behavior.

I spent several hours on this problem and whoever has the time, I would love to learn what the cause of it is.

Thanks!

seanenroute’s picture

Just checking to see if there has been an update on this problem, and if it will be added to a final version of the locations module in the near future. It's an awesome feature that would be extremely helpful to a lot of us.

Cheers, Sean

pcorbett’s picture

I second that... any progress?

bmagistro’s picture

Has anyone had some success with this module patch?

bmagistro’s picture

I couldn't get the patch listed for version 5 above to work, so I took a look at the existing code. with the latest version of the location module, i added the block of code below at line 1423 and it added it to the registration form correctly. I am still working on making the fields required and will update when i have something that is working.

Unfortunately this would make it a semi hard coded change.... (since that is what i need i am ok with it but it might be beneficial to add a control to the admin area that says show on registration page and reference that with this if block.

if ($op == 'register' && $user_setting == LOCATION_USER_COLLECT) {
$form = array(1 => array());
$form[0]['location'] = location_form(array('street', 'city', 'province', 'postal_code', 'country'), (isset($user->location) && !_location_is_empty($user->location)) ? location_api2form($user->location) : array('country' => variable_get('location_default_country', 'us')), array(), variable_get('location_suppress_country', 0) ? array('country' => variable_get('location_default_country', 'us')) : array());
$form[0]['location']['#type'] = 'fieldset';
$form[0]['location']['#title'] = t('Location');
$form[0]['location']['#tree'] = TRUE;
$form[0]['location']['#collapsible'] = TRUE;
$form[0]['location']['#description'] = t('Enter as much of your address as you are comfortable with. Your address will only be viewable by those who have the appropriate permissions. The site will be able to automatically link you to driving directions and other features if it already knows your address.');

if ($user->location['lid']) {
$form[0]['location']['lid'] = array(
'#type' => 'hidden',
'#value' => $user->location['lid']
);
}

return $form;
}

nvoyageur’s picture

StatusFileSize
new946 bytes

I just made a small patch for this that just edits one line of code rather than replicate an entire section.

I've tested it and it presents the location form at registration and stores the submitted info their profile.

It still is not require, but if you have the disclaimer "Enter as much of your address as you are comfortable with...." then required is not an issue.

wildfeed’s picture

Can users be searched by location?

I have included location module fields in the registration process and I'm able to collect user locations and view them using gmap.

How can Search by Location be used to reuturn a list of USERS (uid) that meet the search criteria (proximity)?

"Search by Location" does return a list of nodes if location info is supplied for them.

I would like users to be able to search for other users by proximity then click the IDs of the usernames returned and be directed to the user profiles of the site members they have found.

Any suggestions for this?

Evermore’s picture

I was curious if there had been any more headway on this patch? I love the idea of not having "Street" show up on the information to be submitted, and also would like to see the ability to weight the location input form so it doesn't always rise to the top.

bmagistro’s picture

what i wound up using was civicrm since i wanted the newsletter functions from there. that was easily integrated

cday119’s picture

StatusFileSize
new1.41 KB

Hey everyone,

Just figured this one out with some help from askike's patch

In order to get users to submit their locations, install the locations module

Then enable it and in the module administration page enable user locations.

Then patch location.module with the patch I have attached. This patch makes the zipcode field required for submission

Basically the location.module includes the location.inc file and in that file their is a function called location_form() wich allows you to specify required fields. The code is on line 231.

gonz’s picture

Hi everyone - I am sorry to ask such a NB question, but how do I apply this patch - I looked at line 231 and tried to copy and paste this patch code in there - but that definately did not work.

I looked up "applying patch" in Drupal search, but did not find much info.

Any advice?

cday119’s picture

Ahhh I'm sorry, I' m the noob. I f'ed up the patch,

anyway the code you want to change is on line 1421 of location.module

Line 1421:

    $form[0]['location'] = location_form(array('street', 'city', 'province', 'postal_code', 'country'), (isset($user->location) && !_location_is_empty($user->location)) ? location_api2form($user->location) : array('country' => variable_get('location_default_country', 'us')), array(), variable_get('location_suppress_country', 0) ? array('country' => variable_get('location_default_country', 'us')) : array());

should be

    $form[0]['location'] = location_form(array('street', 'city', 'province', 'postal_code', 'country'), (isset($user->location) && !_location_is_empty($user->location)) ? location_api2form($user->location) : array('country' => variable_get('location_default_country', 'us')), array(PUT REQUIRED FIELD NAMES HERE AND SEPARATE THEM WITH A COMMA), variable_get('location_suppress_country', 0) ? array('country' => variable_get('location_default_country', 'us')) : array());

You can get the available field names from line 233 in location.inc

They are 'name', 'street', 'city', 'province', 'postal_code', 'country'

So if you wanted to require a postal code line 1421 of location.module would be:

-    $form[0]['location'] = location_form(array('street', 'city', 'province', 'postal_code', 'country'), (isset($user->location) && !_location_is_empty($user->location)) ? location_api2form($user->location) : array('country' => variable_get('location_default_country', 'us')), array('postal_code'), variable_get('location_suppress_country', 0) ? array('country' => variable_get('location_default_country', 'us')) : array());
gonz’s picture

That worked Perfectly!!! You guys are amazing.

- I added the code snippet from above
- replaced the code at line 1421.

Now I have this code block from 1419 -1455:

if ($op == 'form' && $category == 'account' && $user_setting == LOCATION_USER_COLLECT) {
$form = array(1 => array());
$form[0]['location'] = location_form(array('street', 'city', 'province', 'postal_code', 'country'), (isset($user->location) && !_location_is_empty($user->location)) ? location_api2form($user->location) : array('country' => variable_get('location_default_country', 'us')), array('street', 'city', 'province', 'postal_code', 'country'), variable_get('location_suppress_country', 0) ? array('country' => variable_get('location_default_country', 'us')) : array());
$form[0]['location']['#type'] = 'fieldset';
$form[0]['location']['#title'] = t('Location');
$form[0]['location']['#tree'] = TRUE;
$form[0]['location']['#collapsible'] = TRUE;
$form[0]['location']['#description'] = t('Enter as much of your address as you are comfortable with. Your address will only be viewable by those who have the appropriate permissions. The site will be able to automatically link you to driving directions and other features if it already knows your address.');

if ($user->location['lid']) {
$form[0]['location']['lid'] = array(
'#type' => 'hidden',
'#value' => $user->location['lid']
);
}

return $form;
}

if ($op == 'register' && $user_setting == LOCATION_USER_COLLECT) {
$form = array(1 => array());
$form[0]['location'] = location_form(array('street', 'city', 'province', 'postal_code', 'country'), (isset($user->location) && !_location_is_empty($user->location)) ? location_api2form($user->location) : array('country' => variable_get('location_default_country', 'us')), array('street', 'city', 'province', 'postal_code', 'country'), variable_get('location_suppress_country', 0) ? array('country' => variable_get('location_default_country', 'us')) : array());
$form[0]['location']['#type'] = 'fieldset';
$form[0]['location']['#title'] = t('Location');
$form[0]['location']['#tree'] = TRUE;
$form[0]['location']['#collapsible'] = TRUE;
$form[0]['location']['#description'] = t('Enter as much of your address as you are comfortable with. Your address will only be viewable by those who have the appropriate permissions. The site will be able to automatically link you to driving directions and other features if it already knows your address.');

if ($user->location['lid']) {
$form[0]['location']['lid'] = array(
'#type' => 'hidden',
'#value' => $user->location['lid']
);
}

return $form;
}

Thanks again for everything.

bdragon’s picture

Status: Needs review » Closed (duplicate)