TOPIC:

Content Builder fill select with database data in edit view 4 weeks 2 days ago #244885

  • Topic Author
  • relsig
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 23
  • Thanks: 0
HelloI manged to replace the number stored in a field by a text from another database table using the item wrap code with the following code
<?php $db = JFactory::getDBO(); 
$sql = "SELECT Kurzform FROM #__osvvereine 
WHERE EDV = " . $db->quote($value); 
$db->setQuery($sql); 
$value = $db->loadResult(); ?>



In the details view and edit view I see the number instead of the text.




Can you please tell me what I have to use and where, so I will get the correct text?

I found the following example to fill a select element with data from a database table
$this->execPieceByName('ff_InitLib'); //Include BreezingForms Library
$db = JFactory::getDBO();//Get Database Object
  
//Create your own query here
$db->setQuery('Select username From #__users '); 
  
$result = $db->loadColumn(); //load the result from the query
$test = "";
for ($i = 0; $i < count($result); $i++)
{
     $test .= "0;".$result[$i].";".$result[$i]."\n";
}
 
function ff_setSelectList($name, $value)
{
     global $ff_processor;
     for ($r = 0; $r < $ff_processor->rowcount; $r++)
     {
          $row =& $ff_processor->rows[$r];
          if ($row->name==$name)
          $row->data2 = $value;
          unset($row);
     } // for
} // ff_setSelectList
 
ff_setSelectList('select1', $test);

Unfortunately this doesn't work in content prepare, since it is made for Breezing Form. Second, the example above uses "0;text1;text1" I would need "0;text1;number

Thank you
Attachments:

Please Log in or Create an account to join the conversation.

Content Builder fill select with database data in edit view 4 weeks 1 day ago #244901

  • tihana.krivic's Avatar
  • tihana.krivic
  • Offline
  • Moderator
  • Moderator
  • Posts: 644
  • Karma: 3
  • Thanks: 75
Hi,

this code is for BF->populate select list with database table. And if you want this code you need to add it in Before Form pieces (your form->Advanced->more options->Form pieces->Before Form->check custom and put code).
If you want populate select list like "0;text1;number", you can put this:
$this->execPieceByName('ff_InitLib');
$rows = ff_select("SELECT id, username FROM #_users");
$listdata = "0;Please select a value;0\n"; //First entry of the select list
for ($i = 0; $i < count($rows); $i++) {
    $listdata .= "0;{$rows[$i]->username};{$rows[$i]->id}\n";
}
ff_setSelectList('NAMEOFSELECTLIST', $listdata);

function ff_setSelectList($name, $value) {
    global $ff_processor;
    for ($r = 0; $r < $ff_processor->rowcount; $r++) {
        $row =& $ff_processor->rows[$r];
        if ($row->name==$name)
            $row->data2 = $value;
        unset($row);
    } // for
} // ff_setSelectList

Regards,
Tihana

Please Log in or Create an account to join the conversation.

Last edit: Post by tihana.krivic.

Content Builder fill select with database data in edit view 4 weeks 1 day ago #244947

  • Topic Author
  • relsig
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 23
  • Thanks: 0
Hi Tihana

Thank you, this answers one question.

What do I have to do if I want this in Content builder?

Thanks

Please Log in or Create an account to join the conversation.

Content Builder fill select with database data in edit view 4 weeks 1 day ago #244950

  • tihana.krivic's Avatar
  • tihana.krivic
  • Offline
  • Moderator
  • Moderator
  • Posts: 644
  • Karma: 3
  • Thanks: 75
Hi,

you can use code like this in the Group definition of the Element:
<?php
$db = JFactory::getDBO();
$db->setQuery("SELECT id, username FROM #__users");
$contents = $db->loadObjectList();
$listdata = "Please select a value;0\n"; 

for ($i = 0; $i < count($contents); $i++) {
                $listdata .= "{$contents[$i]->username};{$contents[$i]->id}\n";
}
$value = $listdata; // that's the important part for contentbuilder
?>

You can find the group definition field in the datastorage options:


Let me know if it works for you

Regards,
Tihana
Attachments:

Please Log in or Create an account to join the conversation.

Content Builder fill select with database data in edit view 3 weeks 3 days ago #245185

  • Topic Author
  • relsig
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 23
  • Thanks: 0
Hi Tihana

Unfortunately I need some more assistance....
What confuses me is that I have to do this in data storage. Why don't I have to do that in a view? (Content prepare or edit prepare)

Table1
EDV; City;
2; Berlin;
1 ; Madrid;

Table2
EDV; Lastname; Firstname; Street....
1; Doe; John; MyStreet;
2; Doe; Jane; Myother street;

What I would like is a view on table2, in content mode there should be the following:
City: Berlin
Lastname: Doe
Firstname: Jane

In edit mode all the fields are prefilled with the information, City is a select element, that contains all cities from table1, so that it can be choosen in edit mode.

Thanks

Roger

Please Log in or Create an account to join the conversation.

Last edit: Post by relsig.

Content Builder fill select with database data in edit view 3 weeks 3 days ago #245193

  • Topic Author
  • relsig
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 23
  • Thanks: 0
Well I made some progress

Using this in data storage for a new element, can't make it with the existing yet...
<?php
$db = JFactory::getDBO();
$db->setQuery("SELECT EDV, Kurzform FROM #__osvvereine");
$contents = $db->loadObjectList();
$listdata = "Bitte Verein wählen;0\n"; 

for ($i = 0; $i < count($contents); $i++) {
                $listdata .= "{$contents[$i]->Kurzform};{$contents[$i]->EDV}\n";
}
$value = $listdata; // that's the important part for contentbuilder
?>

This makes an entry in the database looking like this "0,5272". There is something missing in the listdata variable, but I don't know how to make it correct. Kurzform ist a city name, which is not taken, I also don't know where the 0 comes from.

In details view it shows the following


It should show the name of a city only and not the value. Can you please tell me where to set this correctly.

Thanks

Roger
Attachments:

Please Log in or Create an account to join the conversation.

Moderators: ForumSupport
Time to create page: 0.157 seconds

BreezingForms Pro 1.4.7 for WordPress Released!

Available in the membership section.

Summer Sale!

Massive discounts on all subscriptions!

Get Your Subscription Here

Quick Links

Downloads

BreezingForms

ContentBuilder

BreezingCommerce

Templates

Documentation

BreezingForms

ContentBuilder

BreezingCommerce

Apprendre BreezingForms (French Community)

Apprendre et maîtriser BreezingForms par des tutoriels et exemples, le tout en français

breezingforms.eddy-vh.com

Questions et réponses sur les forums de l'AFUJ

AFUJ

Special Offer

Summer Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!