Forums

[solved] How to pull a cb field into a chrono form?

craude 13 Oct, 2009
Hello,

after hours trying almost everything to put a value of a cb field into a chrono form field a post is my last hope.
I read and tried from php stuff to connectivity - nothing with some result.

It is easy to use this:

<? $user = &JFactory::getUser(); ?>
<label class="cf_text"><?= $user->name; ?></label>

But how do I get a value from a community builder field? This does not work:

<label class="cf_text"><?= $user->xxxx; ?></label> 

(xxxx is a field in cb)

Im not a php guru and all the posts here unfortunately didn't help. I guess I'm not the first newbie how comes across this problem. But where is the solution?

Would appreciate if someone could point me in the right direction, thanks.


setup: Joomla 1.5.14, Chrono 3.1 RC5.5 - 5 domain license
GreyHead 14 Oct, 2009
Hi craude,

You need to tell ChronoForms exactly how to get the data you need.

It's possible that you can do this with the Profile Plugin; otherwise you need to write a MySQL query to get the information from the CB table. This isn't particularly difficult but it's probably worth trying the Profile Plugin first - you'll need to know the name of the CB table and the id column in it.

Bob
rodsdesign 15 Oct, 2009
just in case the plugin doesn't work...
If I had a field called cb_busphone (business phone)

<?php
$user =& JFactory::getUser();
$id=$user->id;

$q="SELECT cb_busphone
FROM jos_comprofiler
WHERE jos_comprofiler.user_id = '$id'";

$r=mysql_query($q);
while ($r2=mysql_fetch_array($r)) 

{
     echo "<h4>Your business phone is " .$r2[cb_busphone] ."</h4>";
}
 ?>


The above grabs the ID from the logged in user, assigns it to $id - grabs their business phone from Community Builder (cb_busphone) and then echos it out to the page. In your instance,
<label class="cf_text"><?php echo $r2[cb_busphone]; ?></label> 
or whatever field you choose.

Also, make sure you use <?php to start your php statement and ?> to end it.

hth
Rod
GreyHead 15 Oct, 2009
Hi craude,

Here's a 'Joomla'd version of Rod's code
<?php
$user =& JFactory::getUser();
$db =& JFactory::getDBO();
$id=$user->id;
$query = "
  SELECT `cb_busphone`
    FROM `#__comprofiler`
    WHERE `user_id` = $id ;
";
$db->setQuery($query);
$cb_bphone = $db->loadResult();
echo "<h4>Your business phone is $cb_bphone</h4>";
?>

NB There will need to be some changes if you need more than one field back from the CB table.

Bob
craude 15 Oct, 2009
Thanks a lot. That was very helpful. I tried both ways after figuring out how the "profile page" plugin works and in my case that plugin does it as well so I use that one in the moment. But I guess I have to go back to the SQL statements when I decide later to not only read the values but also to write those back to the table. I'll see.

Thanks.
This topic is locked and no more replies can be posted.