cebby wrote:
Could you post the solution that worked for you?
I'm looking for a way to edit existing DB items and replace the values via a form. Is this what your solution accomplished?
The functionality I wanted was to reference variables that I set as the form was being loaded (Quickmode! [highlight the form name node] --> Advanced Tab --> More options link --> Form Pieces --> Before Form).
These variables correspond to column values in a single record in a database that I wanted to show automatically in the form when it was loaded.
The first thing I tried was to reference the variable in the value property of an element on the form - this did not work at first owing to scoping problems and my lack of knowledge of PHP - after some reading I used syntax such as <?php return $GLOBALS['variable_name'] ?> in the value property.
However I ended up using an in-built function called ff_setValue(). The following code may help - it is my code to show the selected record from a database:
$this->execPieceByName('ff_InitLib');
$GLOBALS['add_id'] = trim(JRequest::getVar('advert_id', -1));
if ($GLOBALS['add_id'] > -1) {
//Signifies editing of an existing record - let's get the appropriate record using the advertid parameter passed in through the URL
$sql = "SELECT * FROM #__z_pups_for_sale WHERE id = " . $GLOBALS['add_id'] . " ORDER by id";
$advert = ff_select($sql);
//Populate global variables needed for an update.
//Visible
$GLOBALS['cnt_name'] = $advert[0]->cnt_name;
$GLOBALS['phone_1'] = $advert[0]->phone_1;
$GLOBALS['phone_2'] = $advert[0]->phone_2;
$GLOBALS['details'] = $advert[0]->details;
$GLOBALS['title'] = $advert[0]->title;
$GLOBALS['inactive'] = $advert[0]->inactive;
$GLOBALS['county'] = $advert[0]->county;
$GLOBALS['breed'] = $advert[0]->breed;
//Set field values (update)
//Visible
ff_setValue('cnt_name', $GLOBALS['cnt_name']);
ff_setValue('phone_1', $GLOBALS['phone_1']);
ff_setValue('phone_2', $GLOBALS['phone_2']);
ff_setValue('details', $GLOBALS['details']);
ff_setValue('title', $GLOBALS['title']);
ff_setChecked('inactive', $GLOBALS['inactive']);
ff_setValue('date_created', $GLOBALS['date_created']);
}
else {
// New Record
//Hidden
$GLOBALS['userid'] = JFactory::getUser()->id;
ff_setValue('userid', $GLOBALS['userid']);
}