Merge two Profile Fields to show as one Field

trupal218 - August 8, 2009 - 17:46
Project:Views Custom Field
Version:6.x-1.x-dev
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Description

Hello,

I was wondering if someone could help with the following request.
I would like two CCK fields to display as one field in Views.

For example, in the profile registration I fill out 'First Name' field and 'Last Name' field.
In the Views, I would like one field that show "First Name(space)Last Name" using custom views field.

I would truly appreciate any help on this.
Thank you very much in advance.

#1

trupal218 - August 13, 2009 - 15:02
Title:Merging two Fields to show as one» Merge two Profile Fields to show as one Field
Category:feature request» support request

Hello again,
I changed the issue settings to better fit my request.
Is there anyone that can help me with the php coding for the above requirement.
Thank you!

#2

casey - August 13, 2009 - 16:53

1. Add the two fields you want to combine to your view.
2. Exclude them from display (optional).
3. Add a "Custom Field: PHP Code".
4. Find out what variable names your two fields have (use print_r($data) in the PHP Code field).
5. Use something like this in your PHP Code field:

<?php
echo $data->node_data_field_firstname . ' ' . $data->node_data_field_lastname;
?>

#3

trupal218 - September 2, 2009 - 08:41

Thank you very much for your help! I have been studying drupal and php very hard to better understand how to make a website.

Would you happen to know how I could have it "(First Name) [space] (Inital of Last Name)" in the custom field?

#4

casey - September 2, 2009 - 08:59

<?php
echo $data->node_data_field_firstname . ' ' . $data->node_data_field_lastname[0] . '.';
?>

or

<?php
echo $data->node_data_field_firstname . ' ' . substr($data->node_data_field_lastname, 0, 1) . '.';
?>

#5

bmblack - October 28, 2009 - 16:21

I'm sorry, I dont understand these steps. Could somebody explain them in more detail please? I'd REALLY appreciate it.

1. I added two new fields (went into my content types -> user profile -> new field). The two fields I added were: field_firstname and field_lastname.

2. By default they don't display anywhere, so that's good.

3. I'm not sure how to add a "Custom Field: PHP Code".

4. Could somebody explain how to do this?

5. I think if I can get help with steps 3-4, this code would work.

I really appreciate any help!!

Thanks in advance.

 
 

Drupal is a registered trademark of Dries Buytaert.