• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: pre fill fields from Community Builder

pre fill fields from Community Builder 16 years 11 months ago #1541

Hello Alex,

i bought RSform weeks before and was not happy...

But now, when i took a little bit time to browse the forum i found the solutions for my form problems.

So, i can say your component is preety cool and serve my needs :) Thanks for your work !

For me, only one question is open - a nice to have one ;)

How can i pre fill some form field like \"firstname, lastname, username, company\" with content from existing Community Builder fields. \"cb_firstname\" \"cb_company\" and so on.

This would be very usefull for registered users which have to fill a contact form to subscribe for a event.

Do you have a solution for this request? I already browsed your board but could not find a helpfull hint :blush:

Sunny regards from Germany

Kurt Steiner
The administrator has disabled public write access.

Re:pre fill fields from Community Builder 16 years 10 months ago #1629

  • kuhsay
  • kuhsay's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
Did you ever figure out how to do this?

I am able to get the values into a select box but I really want them put into a textbox as the default value, which I can't figure out.

The code below will insert the users email address into a select field called select. (create a new field in your form with id=select and the type=select). Change email to cb_username or whatever field you wish to lookup.
global $my;
$database->setQuery(\"SELECT email FROM #__users WHERE id=$my->id\"«»);
$data = $database->loadObjectList();//we load the usernames
 
foreach($fields as $i=>$field){
    if($field->name=='select'){//cycle through the fields, and find our select box field
        $string = array();
        if(!empty($data)){
            foreach($data as $data_row){
                $string[] = $data_row->email.'|'.$data_row->email;//prepare the default syntax which will be value1|label1,value2|label2
            }
        }
        $string = implode(',',$string);
        $fields[$i]->default_value = $string;
    }
}
<br><br>Post edited by: kuhsay, at: 2008/01/14 20:04
The administrator has disabled public write access.

Re:pre fill fields from Community Builder 16 years 10 months ago #1680

  • alex
  • alex's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 443
  • Thank you received: 3
Hi guys,

here's how this should be done. So, we assume that you have added some fields in your CB.

Edit your form, and create equivalent fields for the CB fields. Assuming that you want to use the cb fields: email, firstname, lastname, then go to the Scripts tab, and in Scripts called on form display: paste this code:
//load the CB fields
$database-&gt;setQuery(\&quot;SELECT * FROM #__comprofiler_fields WHERE published&gt;0\&quot;«»);
$cb_fields = $database-&gt;loadObjectList();
 
global $my;
//cycle through the RSform fields
foreach($fields as $i=&gt;$field){
    //check if there is an equivalent field in CB
    foreach($cb_fields as $j=&gt;$cb_field){
        if($field-&gt;name == $cb_field-&gt;name{
            //if we find the equivalent, we load the value
            if($cb_field-&gt;table=='#__users') $key = 'id';
            else $key = 'user_id';
            $database-&gt;setQuery(\&quot;SELECT {$cb_field-&gt;name} FROM {$cb_field-&gt;table} WHERE {$key} = {$my-&gt;id}\&quot;«»);
            $fields[$i]-&gt;default_value = $database-&gt;loadResult();
        }
    }
}
The administrator has disabled public write access.

Re:pre fill fields from Community Builder 16 years 10 months ago #1704

Hello Alex,
many thanks for that solution - i will try this and come back with my feedback :-)

Sunny regards from Germany

Kurt Steiner
The administrator has disabled public write access.

Re:pre fill fields from Community Builder 16 years 10 months ago #1709

  • mlarsen
  • mlarsen's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 1
Alex,

I've added the field names the same in the form as they are in the database, with the exception that the field names don't have the underscore that CB builds in with user defined fields, for example I set the name as cbaddress in the form for a field that is cb_address in the database. What code (or other) changes need to be made to link the form field with the database field given the inability to add underscores to the form field name?

Thanks for your help!

Mark
The administrator has disabled public write access.

Re:pre fill fields from Community Builder 16 years 9 months ago #2132

Hi Alex,

I get the following parse error with the above code.

Parse error: syntax error, unexpected T_IF in
*\components\com_forme\forme.html.php(1) : eval()'d code(13) : eval()'d code(2) : eval()'d code on line 12

It must be something simple but unfortunately my php is not up to scratch (yet)

Many thanks
Iain
The administrator has disabled public write access.

Re:pre fill fields from Community Builder 16 years 9 months ago #2166

  • alex
  • alex's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 443
  • Thank you received: 3
Hi Mark, Iain,

you should use this code then:
//load the CB fields
$database->setQuery("SELECT * FROM #__comprofiler_fields WHERE published>0");
$cb_fields = $database->loadObjectList();
 
global $my;
//cycle through the RSform fields
foreach($fields as $i=>$field){
    //check if there is an equivalent field in CB
    foreach($cb_fields as $j=>$cb_field){
        if('cb_'.$field->name == $cb_field->name){       //notice the additional cb_ 
            //if we find the equivalent, we load the value
            if($cb_field->table=='#__users') $key = 'id';
            else $key = 'user_id';
            $database->setQuery("SELECT {$cb_field->name} FROM {$cb_field->table} WHERE {$key} = {$my->id}");
            $fields[$i]->default_value = $database->loadResult();
        }
    }
}
 
Last Edit: 15 years 9 months ago by octavian.
The administrator has disabled public write access.

Re:pre fill fields from Community Builder 16 years 9 months ago #2167

That's got it - many thanks Alex. B)

As a suggestion - should this thread be moved to the \"scripts\" section - I am sure many people will find it useful.

All the best
Iain
The administrator has disabled public write access.

Re:pre fill fields from Community Builder 16 years 8 months ago #2431

Hi, thanks for the component. This snippet you posted works great for fields that have been added to the CB profile, but it is not bringing in the default fields (firstname, lastname, email). Any ideas on how to pull the default profile fields (without the cb_) and additional profile fields (with cb_)? I'm using J1.5 and CB1.1.

Thanks,
Patrick<br><br>Post edited by: HawkMultimedia, at: 2008/03/16 02:57
The administrator has disabled public write access.

Re:pre fill fields from Community Builder 16 years 5 months ago #3537

Unfortunately this isn't working for me. I've pasted the code into the \"Script called on form display \" window and saved the form. When I refresh the page I get the following error:
Warning: Invalid argument supplied for foreach() in /****/components/com_rsform/controller/functions.php(834) : eval()'d code on line 7

Line 7 reads
foreach($fields as $i=&gt;$field){

This site is on Joomla 1.0.15, CB 1.2, MYSQL 5, and as a MYSQL noob I can't fathom out what the problem is. (Obvious things like am I logged in are not an issue!)

Has anyone had this problem and solved it please?
The administrator has disabled public write access.

Re:pre fill fields from Community Builder 16 years 5 months ago #3538

duplicate message deleted<br><br>Post edited by: shaun.macintosh, at: 2008/07/01 15:53
The administrator has disabled public write access.

Re:pre fill fields from Community Builder 16 years 5 months ago #3541

  • dragonjc
  • dragonjc's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 151
It is beacause you work on RS!Forms Pro Maybe, the script doesn't fonctionned on RS§Forms >Pro because, they can't used the $fields var from class SManager. So you are chocolate ^^
or try this :

It's the same think like this :
http://www.rsjoomla.com/index.php/RSform-Scripts/3493-RePre-fill-Name-email-address-if-user-is-lo.html#3493

but with CB data fields, so

Assign an only crazy value like this one : *-*-* into the Default Value of the input you want pre-filled.

and paste this code :
$my = &amp; JFactory::getUser();
if($my-&gt;id){
$database-&gt;setQuery(\&quot;SELECT * FROM #__comprofiler_fields WHERE user_id = {$my-&gt;id}\&quot;«»);
$cb_fields = $database-&gt;loadObjectList();
 
$formLayout = str_replace(\&quot;*-*-*\&quot;, cb_fields-&gt;name, $formLayout);
}
Else {
$formLayout = str_replace(\&quot;*-*-*\&quot;, \&quot;Insert here your name\&quot;, $formLayout);
}

Explain of my test :
- I defined $my with the user information array
- If user is connected :
- Build the mysql query with field of connected people
- I replace the defaut value by the value take of the row \"name\" from my array
- Else
- I replace the defaut value by the value of my choice

Don't forget to log on front end.

I can't test them because i don't want the CB component . But maybe it will be ok, it have fonctionne with the original users table from joomla. if there is a problem it's came from the mysql query becaus i don't know the tree of mysql database with CB Component.



Alex, please, build an alone section for RS!Foprms Pro, it is very useful, we can't be up on this new component if we used RS!Forms Lite script. An you will have less same message of non fonctionned.
<br><br>Post edited by: dragonjc, at: 2008/07/01 21:43
Component RS SHow Form in build
The administrator has disabled public write access.

Re:pre fill fields from Community Builder 16 years 5 months ago #3552

  • adrian_m
  • adrian_m's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 7
Dragonjc, thank you. Actually the person with the question (shaun) is the owner of the RSForms Pro license, I was developing his web site, so your reply is actually for me ;) .

I tore my hair out trying to make this and other scripts work with RSFormsPro. The problem seems to be at the first step, the code (and variations) simply will not work:
$database-&gt;setQuery(\&quot;SELECT * FROM #__comprofiler_fields WHERE user_id = {$my-&gt;id}\&quot;«»);

$cb_fields = $database-&gt;loadObjectList();

You are correct: :woohoo: RSForms Pro can't use the $fields var from class SManager. So even though your idea of the crazy value strings DOES work - it is brilliant - it does not work on CB fields when I cannot load them.

To check this and to see if I was going crazy or not - looking for typing errors and everything - I made copy web site but using basic RSForms, NOT \"Pro\". I installed the code recommended above by alex on a test form, and it works perfectly! (Thanks alex) Unfortunately Now I have to redesign my system around RSForms, which means making new forms, I don't get the same facilities as in Pro AND I have to buy a new license!

FEATURE REQUEST - Change RSForms Pro to use the $fields var from class SManager!
The administrator has disabled public write access.

Re:pre fill fields from Community Builder 16 years 5 months ago #3554

  • dragonjc
  • dragonjc's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 151
Ok, no problem.
Keep the Pro version, his more powerful, and script will came.

Try this :
global $database;
$database = mysql_query(\&quot;SELECT * FROM #__comprofiler_fields WHERE user_id = '$my-&gt;id'\&quot;);
$query = mysql_fetch_assoc($database);
$cb_fields = $query-&gt;loadObjectList();

I'm not sure if global is good, but i try something like this a few day ago for another script, and i was ok with \"global\" and not without.

If it doesn't fonctionned, can you search the mysql database who was used by CB and if they use the jos_users. If they use it, it is more easy.

Post edited by: dragonjc, at: 2008/07/02 13:15

Post edited by: dragonjc, at: 2008/07/02 13:29<br><br>Post edited by: dragonjc, at: 2008/07/02 13:30
Component RS SHow Form in build
The administrator has disabled public write access.

Re:pre fill fields from Community Builder 16 years 5 months ago #3662

  • deaffe
  • deaffe's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 1
Hello,

I have the same problem.... Since i am not a coder it's but i am not stupid either.....or am i :woohoo:

I have RSforms Pro with joomla 1.5

I want to have a select list with data from a specific table in the joomla database. In this case I want the selectlist filled with the category names of the contact section \"com_contacts_details\" where the select1 is my selectlist. I get the error \"Fatal error: Call to a member function on a non-object\"

What is going wrong?? I am out of my google resources :ohmy:
global $database;
$database = mysql_query(\&quot;SELECT name FROM ag_categories WHERE section =  'com_contact_details'\&quot;«»);
$query = mysql_fetch_assoc($database);
$cb_fields = $query-&gt;loadObjectList();


Maybe it is a good idea to add the $fields var from class SManager????<br><br>Post edited by: deaffe, at: 2008/07/10 12:33
The administrator has disabled public write access.

Re:pre fill fields from Community Builder 16 years 5 months ago #3670

  • dragonjc
  • dragonjc's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 151
not i have do a suggestion to custom more easy the component, just wait a small.With this do a select list from an other table, pre fileld from all other table,... is a kind game...

So juts wait a small.
If it doesn't coming sson, i will help you.
Component RS SHow Form in build
The administrator has disabled public write access.

Re:pre fill fields from Community Builder 16 years 4 months ago #3689

  • Bandit
  • Bandit's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
As a newcomer to RSform, Joomla & Community Builder I have a lot of catching up to do but I just wanted a quick check that with the above I can achieve my goal...

I'll try & explain. I hope to have an additional read only user field in Community Builder that's an email address completed by an administrator (that isn't the user or administrator email address but a third party one). In one of my RSforms I need the user completed form to be emailed to the third party email address that's in that users additional Community Builder field (it will be a different address depending on the particular user) plus probably a copy to the administrator.

Is that possible with the above code?
The administrator has disabled public write access.

Re:pre fill fields from Community Builder 16 years 3 months ago #4419

Alex

I use the script you post #2166

But it d
isplay an error

Parse error: syntax error, unexpected T_STRING in /components/com_rsform/controller/functions.php(870) : eval()'d code on line 2<br><br>Post edited by: andrecool, at: 2008/08/25 20:29
Attachments:
The administrator has disabled public write access.

Re:pre fill fields from Community Builder 16 years 3 months ago #4571

  • ejde
  • ejde's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
I'm getting the exact same error. (T_STRING) on line 2.
The administrator has disabled public write access.

Re:pre fill fields from Community Builder 16 years 1 month ago #5489

Hello,

I need the default value is set from the GET request.

I put this code in display script section:
I tried writting this code in rsform display script.
foreach($fields as $i=&gt;$field)
if($field-&gt;name == 'name')
$fields[$i]-&gt;default_value = $_GET['name'];

But the default value is not set.

Someone has any idea ?

Thanks in advance
The administrator has disabled public write access.

Re:pre fill fields from Community Builder 16 years 1 month ago #5490

I have created a log file and seems to be all fine, instead the default value is not set.

If the URL to call the form is like:
http://manou-laptop/joomla/index.php?option=com_forme&amp;Itemid=34&amp;fid=1&amp;name=jm
and my script (on display script section) is like:
foreach($fields as $i=&gt;$field) {
  if($field-&gt;name == 'name') {
    $fields[$i]-&gt;default_value = $_GET['name'];
    file_put_contents(\&quot;/tmp/debug.log\&quot;,\&quot;\n\&quot;.$field-&gt;name.\&quot;-&gt;\&quot;.$_GET['name'],FILE_APPEND);
  }
}

and my debug file has:
name-&gt;jm

So the GET REQUEST works in the script, the field is well identified, but the default value is not set to the field.

How do I make this funcionality ?

Thanks in advance.
The administrator has disabled public write access.

Re:pre fill fields from Community Builder 16 years 1 month ago #5494

Well, I don't know why, probably due to a caching... after a while my approach has worked as I expected.

My problem is fixed following the tips from this thread :)
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!