• 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: Article Custom Field as Form Fields Default Value

Article Custom Field as Form Fields Default Value 2 years 9 months ago #41317

  • gunerguk
  • gunerguk's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 29
  • Thank you received: 3
Is there anyone who could explain with a real sample code how to call a joomla article custom field values to an RSForm Pro form field? I'm sure this would make benefit many RSForm Pro users.

Let's say you have product and set it's price in a custom field and want to make it default value of a forms field when you call the form inside that article.

I searched all over and there is no sample for this situation.
The administrator has disabled public write access.

Article Custom Field as Form Fields Default Value 2 years 4 months ago #41660

  • pmarty
  • pmarty's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 6
  • Thank you received: 1
Hello,
I faced the same problem. With some tests I achieve to populate a field with a value from a custom field.
Here's my way.

First, in the Joomla Fields Manager you need to note what is the ID of the field you are interested in.
In my following example the field ID is 5

Then in your Form, fill the Default Value area with the following code:
//<code>
$articleid=JFactory::getApplication()->input->getInt('id');  //gets the article's ID from the URL
$db = JFactory::getDBO();  //opens a new database connection
$db->setQuery("SELECT `value` FROM #__fields_values WHERE `item_id`='$articleid' AND `field_id`='5' "); //gets the article's custom field value based on its ID (here 5 for the custom field)
$result=$db->loadResult();
return $result;
//</code>

I hope it helps
The administrator has disabled public write access.
The following user(s) said Thank You: gunerguk

Article Custom Field as Form Fields Default Value 2 years 3 months ago #41694

  • gunerguk
  • gunerguk's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 29
  • Thank you received: 3
Hi pmarty,

I just tested your solution on local server. It works great as I expected. Thank you very much. I hope this helps also to other users.
The administrator has disabled public write access.

Article Custom Field as Form Fields Default Value 10 months 3 weeks ago #42752

Hello, is there a way to load the value of that custom field from a specific article? Best case: User make a selection in a dropdown (an article) and depending on the selection a text field gets prefilled with the value of the custom field of the article.
The administrator has disabled public write access.

Article Custom Field as Form Fields Default Value 10 months 3 weeks ago #42755

  • pmarty
  • pmarty's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 6
  • Thank you received: 1
Hello,
Sorry but I'm not able to help you for such a development :(
I hope you'll find someone else here.
The administrator has disabled public write access.

Article Custom Field as Form Fields Default Value 10 months 3 weeks ago #42756

Thank you for your reply! :)

I thought it would be possible to adjust this code to do that. It pulls the value of the field id 8 from the article id 64 in to a textfield and it works fine. But when I put this code into a dropdown I get a syntax error. I'd like to define multiple article ids where to pull the field id 8 from and list it in a dropdown. Any help getting closer is appreciated.
//<code>
$db = JFactory::getDBO();  //opens a new database connection
$db->setQuery("SELECT `value` FROM #__fields_values WHERE `item_id`='64' AND `field_id`='8' ");
$result=$db->loadResult();
return $result;
//</code>
Last Edit: 10 months 3 weeks ago by T.Venugopal.
The administrator has disabled public write access.

Article Custom Field as Form Fields Default Value 10 months 3 weeks ago #42757

This get me no results:
//<code>
// Prepare the empty array
$items = array();
// Prepare the database connection
$db = JFactory::getDBO();
// Keep this if you'd like a "Please select" option, otherwise comment or remove it
$items[] = "|Master-LP wählen (WBKZ-Default)[c]";
 
$db->setQuery("SELECT `value` FROM #__fields_values WHERE `item_id`='64' AND `field_id`='8' ");
$db->setQuery("SELECT `value` FROM #__fields_values WHERE `item_id`='968' AND `field_id`='8' ");
$result=$db->loadObjectList();
 
// Now, we need to convert the results into a readable RSForm! Pro format.
// The Items field will accept values in this format:
// value-to-be-stored|value-to-be-shown
// Eg. m|M-sized T-shirt
foreach ($results as $result) {
  $value = $result->id;
  $label = $result->title;
  $items[] = $value.'|'.$label;
}
 
// Multiple values are separated by new lines, so we need to do this now
$items = implode("\n", $items);
 
// Now we need to return the value to the field
return $items;
//</code>
The administrator has disabled public write access.

Article Custom Field as Form Fields Default Value 10 months 3 weeks ago #42766

Solution:
 
//<code>
// Replace the array entries with the desired article IDs
$article_ids = array(64, 968, 428,196, 197);
 
$results = array();
 
foreach ($article_ids as $id) {
    $db = JFactory::getDBO();
    $db->setQuery("SELECT value FROM #__fields_values WHERE item_id='$id' AND field_id='8'");
    $result = $db->loadObjectList();
 
    // Load the title of the article
    $db->setQuery("SELECT title FROM #__content WHERE id='$id'");
    $title = $db->loadResult();
 
    // Add the result to the results list
    $results[] = array('value' => $result[0]->value, 'label' => $title.' ('.$result[0]->value.')');
}
 
// Convert the result into an RSform Pro-readable format
$items = array();
$items[] = 'Master-LP mit Standard-WBKZ wählen'; // Platzhalter hinzufügen
foreach ($results as $result) {
    $value = $result['value'];
    $label = $result['label'];
    $items[] = $value.'|'.$label;
}
 
return implode("\n", $items);
 
//</code>
 
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!