1 (edited by FionaCEDaR 17-10-2012 11:26:12)

Topic: Copy field values from user profile SOLVED

Hi,
I am having trouble getting the first name and last name from the user profile to show in the recording form when a user is logged in. The email address shows ok though! I have the Easy login and Profile modules enabled. I had this problem on my test site but this doesn't appear to be the same problem. Any ideas?
Thanks,
Fiona

Fiona McCrory
CEDaR Website Officer
www.nmni.com/cedar

2

Re: Copy field values from user profile SOLVED

Hi Fiona,

I've been on leave the past couple of weeks so perhaps you have already fixed this yourself. The first obvious things to check are that, in the user interface, section of your form configuration that you have checked "Show user profile fields even if logged in" and "Copy field values from user profile". Moreover, in order for the system to know that a Drupal profile field maps on to an Indicia sample attribute, the correct naming convention must be used. Written in PHP, the name of the profile field must be

'profile_'.strtolower(str_replace(' ','_',$attribute['caption']))

so a custom attribute of 'First Name' will be populated with a value if there is a profile field called 'profile_first_name'

Of course, now you are using the Easy Login module, when samples are created they are tagged with the Indicia User Id of the recorder and their Indicia user record contains their name so you might consider whether you also need to record their name with sample attributes. One reason to do so is that people may change their name, updating their Indicia user record so, by recording the name with the sample, you are capturing their name at the time of recording.

Jim Bacon.

3

Re: Copy field values from user profile SOLVED

Hi Jim,
Thanks for this. I now know what I did wrong but am not quite sure how to fix it. The form I'm working on is entirely public so people do not have to register with the site, I therefore have made it a requirement that the recorder adds their email address, first name and last name.

When setting up the attributes for the survey on the warehouse1 I used "First name (required)" and "Last name (required)" instead of "First name" and "Last name". The first options are not part of the profile and so don't get copied onto the form. Seems very obvious now!!

What I'd like to do is change the form to use "First name" and "Last name" but it is a live form with records already added which I don't want to risk losing information for.

The alternative is to keep using the ones I have and alter the profile settings of my site. The problem there is that I don't know how to reference these fields in the profile settings as brackets aren't allowed.

Any thoughts?

Fiona

Fiona McCrory
CEDaR Website Officer
www.nmni.com/cedar

4

Re: Copy field values from user profile SOLVED

Hi Fiona

I can think of two solutions to your problem.

The first is to hack the code so that ' (required)' is stripped off the attribute caption before comparing with the names of profile fields. Simply done, in one line of code, but needing to be reinstated every time you upgrade the iform module. I would call that bad practise.

The alternative is to reconfigure on the warehouse to use custom attributes with captions 'First Name' and 'Last Name' and manage the consequences. I would expect the following:

  • The attributes can be made required on a per-survey basis by going to Lookup Lists > Surveys, finding your survey, clicking on Setup Attributes and clicking Edit for the attribute you want to modify. Check the box labelled required and then Save.

  • Clear the cache on your web site and the new attributes start being used, hopefully with values filled from the profile, when a user is logged in.

  • When you make this change, all the names that you have collected to date will remain in the database but tagged with the id of an attribute that is no longer part of the survey. Effectively the information has been orphaned.

  • Wherever data is output automatically, based on the survey definition, the old name values will be missing.

  • Any reports that refer to attributes explicitly by id will show old name values but not the new ones. (You probably don't have any such reports.)

Clearly the poor wee orphans need adopting. The solution to this is for me to run an update on the database so that I reassign all the custom attribute values you have collected for 'First Name (required)' (id=6) to 'First Name' (id=36) and 'Last Name (required)' (id=7) to 'Last Name' (id=58).

This is all quite painless but it is also all theory. We ought to try this on testwarehouse first

I have found the use of public custom attributes a bit of a double-edged sword myself. Had you created your own custom attributes for first name and last name the solution would have been as simple as changing the caption.

I suggest we continue by email correspondence and report back our conclusion to the forum.

Jim Bacon.

5

Re: Copy field values from user profile SOLVED

Just an update to say we got this problem sorted painlessly. I changed over the attributes to the correct ones and then Jim updated the database, moving the orphaned names to the correct columns.

Many thanks Jim for your help.

Fiona McCrory
CEDaR Website Officer
www.nmni.com/cedar

6

Re: Copy field values from user profile SOLVED

For the record, the two queries I ran were as follows.

update sample_attribute_values sav
set sample_attribute_id = 36
from samples s, surveys sv, websites w
where s.id = sav.sample_id and s.deleted = false
and sv.id = s.survey_id and sv.deleted = false
and w.id = sv.website_id and w.deleted = false
and w.id = 29
and sav.sample_attribute_id = 6

update sample_attribute_values sav
set sample_attribute_id = 58
from samples s, surveys sv, websites w
where s.id = sav.sample_id and s.deleted = false
and sv.id = s.survey_id and sv.deleted = false
and w.id = sv.website_id and w.deleted = false
and w.id = 29
and sav.sample_attribute_id = 7

These say, change the sample_attribute_id to 36 (or 58) for all sample attribute values that currently have the value 6 (or 7) and belong to the samples that belong to the surveys that belong to the website that is Fiona's (while ignoring any stuff that has been deleted)

Jim Bacon