Retrieving item data e.g. for use in RSforms

244Retrieving item data e.g. for use in RSforms/documentation/faq/79-forms-and-submission/244-retrieving-item-data-eg-for-use-in-rsforms.html

Click to subscribe

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 dataif($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 dataif($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 FIELDif($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;

To get the label instead of the value of indexed fields (fields that have a value::label) like radio, radioimage, checkbox, checkboximage, select, selectmultiplereplace:return $itemdata->value;with: