You'll find here an example that you can follow and adapt to suit your needs:
In "administrator/components/your_component/models/" directory, create (if not exists) the directory and file "fields/totalprice.php"
In the "totalprice.php" file place the sample code you'll find below, and code it to your desired needs.
In your "models/forms/" directory, find the xml file that will be called to build the form and then create the custom field like:
<field name="totalprice" type="text" label="COM_CONTENT_TOTAL_PRICE_LABEL" description="COM_CONTENT_TOTAL_PRICE_DESC" class="input-xlarge" size="30" required="true" labelclass="control-label" />
Code sample for the totalprice.php file
<?php
defined('_JEXEC') or die('Direct Access to this location is not allowed.');
//defined('JPATH_BASE') or die; TODO CHECK THIS
jimport('joomla.form.formfield');
/**
* Created by custom field class
*/
class JFormFieldTotalPrice extends JFormField
{
/**
* The form field type.
* @access protected
* @var string
*/
protected $type = 'totalprice';
/**
* Method to get the field input markup.
* @access protected
* @return string The field input markup.
*/
protected function getInput()
{
// Initialize variables.
$html = array();
//Load user example. REPLACE WITH YOU CODE
$html[] = '<input type="text" name="totalprice" value="' . $your_data->value . '" />';
return implode($html);
}
}
?>