Question

I need to create a new Custom Field in Joomla 3.1. but y can't do it. I encountered few articles about create custom Forms in Joomla 2.5 but in this new version i can't.

anyone would help me, i need create custom field in Article backend in joomla 3.1 not in joomla 2.5.

in this case, i need create in back-end joomla article.

<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" />
Was it helpful?

Solution

You'll find here an example that you can follow and adapt to suit your needs:

  1. In "administrator/components/your_component/models/" directory, create (if not exists) the directory and file "fields/totalprice.php"

  2. In the "totalprice.php" file place the sample code you'll find below, and code it to your desired needs.

  3. 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);
    }
}
?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top