Elxis CMS Forum

Support => General => Topic started by: vojodi on June 24, 2008, 13:54:51

Title: problem with calling exfra field value
Post by: vojodi on June 24, 2008, 13:54:51
Hi, I am a new user in Elxis and many thanks from Elxis team, Datahell, all members and dear Farhad Sakhaei for persian translation.
I Have a problem…
I can call the user details to content from this script:
<?php
global $my;
if ($my->name != '') return $my->name;
?>
And it works fine.
But I have created some extra field as (phone, address and etc.).
I don’t know how I can call these field values to my content or forms.
This is the form named your details, in user menu.
<td><input class="inputbox" type="text" name="name" value="vojodi" size="40"
……..
<td colspan="2"><span style="width:130px;">tel*: </span><input type="text" name="efield[2]" value="" maxlength="50" id="req2">
……..
There is a difference between main registration form and extra field.
Extra field name is (efield[2]) not problem. But I will call this value and can not.
Title: Re: problem with calling exfra field value
Post by: datahell on June 24, 2008, 15:07:43
See function profile in component user.
File: components/com_user/user.php

I paste here the relative lines:

Code: (php) [Select]
<?php 
$usrfields explode("|"$row->extrafields);

    if (( 
count($usrfields) > 0) && (trim($usrfields) != &#39;&#39; ) ) {
//$ufields is an array having as key the extraid and value the extra field value for the selected user
$ufields = array();
foreach ($usrfields as $usrfield) {
$uf preg_split("/[\=]/"$usrfield2);
$ufid intval($uf[0]); //if invalid then extraid=0
        
$ufval preg_split(&#39;/[\/]+/&#39;, $uf[1], -1, PREG_SPLIT_NO_EMPTY);
        
if ( count($ufval) < ) { $ufval = array(&#39;&#39;); }

if (($ufid != 0) && ($ufid != &#39;&#39;)) {
$ufields[$ufid] = $ufval;
}
}

    
$query "SELECT extraid, name FROM #__users_extra WHERE published=&#39;1&#39;"
    
."\n AND profile=&#39;1&#39; AND etype<>&#39;hidden&#39; ORDER BY ordering ASC";
$database->setQuery$query );
$exxs $database->loadObjectList();

    
for ($i 0$i<count($exxs); $i++) {
    
$exx = &$exxs[$i];
$eid $exx->extraid;
    
if ( isset($ufields[$eid]) && eUTF::utf8_trim($ufields[$eid][0]) != &#39;&#39; ) {
    
$lists[&#39;extra&#39;] .= &#39;<tr><td><strong>&#39;.$exx->name.&#39;:</strong></td><td>&#39;.implode(&#39;, &#39;, $ufields[$eid]).&#39;</td></tr>&#39;._LEND;
    
}
}
}
?>
Title: Re: problem with calling exfra field value
Post by: datahell on June 24, 2008, 15:19:03
User's extra fields is a string that contains user's extra fileds values in this format:

$row->extrafields = 'extrafield_id1=extrafield_value1|extrafield_id2=extrafield_value2|extrafield_id3=extrafield_value3|......';

As you see different Extra fields are separated by "|".

Now, If the extra field is a checkbox it might have more than one values. So the extrafield_value could have multiple values separated by "/".
Example contents of extrafield_value: "blue/red/pink"

Here is a sample real string:

$row->extrafields = '1=Athens|3=red/green|6=180|......';

Where the first field could be: City (id =1, value: Athens)
the second: Favorite colors: (id = 3, values: red and green)
and the third: height in cm: (id = 6, value: 180)

The names of the extra fields should be taken from the #__users_extra database table.
Title: Re: problem with calling exfra field value
Post by: Farhad Sakhaei on June 25, 2008, 00:44:20
Hi Mr. Vojoodi ,
Nice to see u here in Elxis world ...
I'll reply to your email soon  ;)
Title: Re: problem with calling exfra field value
Post by: vojodi on June 25, 2008, 17:21:32
Thank you for the trouble and your reply.
Your intelligence was benefic and helpful.
But I have problem to understand.
Please pay attention, simply when I write:

<?php
global $my; return $my->name;?>

It shows the name of user, like (vojodi).
But when I Write:
<?php
global $my; return $my->efield2;?>

Doesn’t show my extrafield value.
Title: Re: problem with calling exfra field value
Post by: Farhad Sakhaei on June 25, 2008, 17:53:28
datahell
اشاره به یك جزء در
Elxis 2008
كرد كه درواقع وظیفه نمایش نیمرخی از كاربر (صفحه شخصی كاربر) داره
كدی كه ارائه كرد مربوط به این جزء هست

آقای وجودی عزیز ، اگر می تونید امشب با من تماس بگیرید ، من منتظر هستم ;)
Title: Re: problem with calling exfra field value
Post by: datahell on June 25, 2008, 17:56:45
You can not access extra user fields from within the $my object! You can not even access them directly by a simple SQL query. You need to manipulate the contents of the "extrafields" database column located in #__users table the way I show you.
Title: Re: problem with calling exfra field value
Post by: vojodi on June 26, 2008, 15:31:39
I am grateful for your helps.
I will try this way and tell you results.