Breadcrumbs
Home / Documentation / FAQ / Forms and submission / Retrieving item data e.g. for use in RSformsRetrieving item data e.g. for use in RSforms
- Retrieving a basic field of the item, like title and category title:
$db = & JFactory::getDBO(); // Set a different item id if you don't want the current item ... $fcitem_id= JRequest::getInt('id',0); $fccat_id= JRequest::getInt('cid',0); $view= JRequest::getVar('view'); if ($view!='items' && $view!='item' && $view!='article') { return "not in items view"; } // RETRIEVE item data if ($fcitem_id) { $query = 'SELECT c.*' .' FROM '.'#'.'__content AS c ' .' WHERE c.id = ' . $fcitem_id; $db->setQuery($query); $itemdata = $db->loadObject(); $item_title = $itemdata->title; } // NOTE $itemdata now CONTAINS all item's basic fields // (but not values for FLEXIcontent fields) // RETRIEVE item's category data if ($fccat_id) { $query = 'SELECT c.*' .' FROM '.'#'.'__categories AS c' .' WHERE c.id = ' . $fccat_id; $db->setQuery($query); $catdata = $db->loadObject(); $cat_title = $catdata->title; } // NOTE $catdata now CONTAINS all item's category basic fields // FINAL STEP: --IF-- your code is for using in a RSform field // then you need to return it: // so, USE ONE of the following return statements // e.g. return $item_title; //e.g. return $cat_title; // e.g. return $item_title ." - ".$cat_title;
- Retrieving the value of a custom field:
$db = & JFactory::getDBO(); // Set a different item id if you don't want the current item ... $fcitem_id= JRequest::getInt('id',0); $fccat_id= JRequest::getInt('cid',0); $view= JRequest::getVar('view'); if ($view!='items' && $view!='item' && $view!='article') { return "not in items view"; } $field_id=45; // CHANGE THIS TO THE ID OF YOUR FIELD if ($fcitem_id) { $query = 'SELECT c.title, c.alias, f.value' .' FROM '.'#'.'__content AS c ' .' LEFT JOIN '.'#'.'__flexicontent_fields_item_relations AS f' .' ON f.item_id = c.id AND f.field_id='.(int)$field_id .' WHERE c.id = ' . $fcitem_id; $db->setQuery($query); $itemdata = $db->loadObject(); $item_title = $itemdata->title; } return $itemdata->value;
NOTE: Click to make this item favourable to be notified of updates
ALSO read this article:
-- Retrieving the HTML DISPLAY of FC fields inside 3rd-party code


