2

I am new to joomla. I have been facing a problem that I want to change Joomla Form values for example when a user enters anything into form fields I want to enter my own values with user input. ie if user enters in text field name and User enters his name John then I want to add netnock after John through backend.
Here is Joomla form

        <?xml version="1.0" encoding="utf-8"?>
    <form>
        <fieldset>
            <field
                    name="id"
                    type="hidden"
                    />
            <field
                    name="name" <!-- I want to add my values to this field -->
                    type="text"
                    label="Enter Name:"
                    description="COM_FORMMANAGER_FORMMANAGER_NAME_DESC"
                    size="40"
                    class="inputbox"
                    default=""
                    />
        </fieldset>
        <field name="types" type="list" default="" label="Select Field Types:" description="">
      <option value="text">text</option>
      <option value="email">email</option>
        <option value="password">password</option>
        <option value="textarea">textarea</option>

    </field>
    </form>


Here is Model

        <?php
    /**
     * @package     Joomla.Administrator
     * @subpackage  com_formmanager
     *
     * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
     * @license     GNU General Public License version 2 or later; see LICENSE.txt
     */

    // No direct access to this file
    defined('_JEXEC') or die('Restricted access');

    /**
     * FormManager Model
     *
     * @since  0.0.1
     */
    class FormManagerModelFormManager extends JModelAdmin
    {
        /**
         * Method to get a table object, load it if necessary.
         *
         * @param   string  $type    The table name. Optional.
         * @param   string  $prefix  The class prefix. Optional.
         * @param   array   $config  Configuration array for model. Optional.
         *
         * @return  JTable  A JTable object
         *
         * @since   1.6
         */
        public function getTable($type = 'FormManager', $prefix = 'FormManagerTable', $config = array())
        {
            return JTable::getInstance($type, $prefix, $config);
        }

        /**
         * Method to get the record form.
         *
         * @param   array    $data      Data for the form.
         * @param   boolean  $loadData  True if the form is to load its own data (default case), false if not.
         *
         * @return  mixed    A JForm object on success, false on failure
         *
         * @since   1.6
         */
        public function getForm($data = array(), $loadData = true)
        {
            // Get the form.
            $form = $this->loadForm(
                'com_formmanager.formmanager',
                'formmanager',
                array(
                    'control' => 'jform',
                    'load_data' => $loadData
                )
            );

            if (empty($form))
            {
                return false;
            }

            return $form;
        }

        /**
         * Method to get the data that should be injected in the form.
         *
         * @return  mixed  The data for the form.
         *
         * @since   1.6
         */
        protected function loadFormData()
        {
            // Check the session for previously entered form data.
            $data = JFactory::getApplication()->getUserState(
                'com_formmanager.edit.formmanager.data',
                array()
            );

            if (empty($data))
            {
                $data = $this->getItem();
            }

            return $data;
        }
    }
Zain Farooq
  • 2,956
  • 3
  • 20
  • 42

1 Answers1

1

Assuming you are following joomla guidelines and architecture in your component, you can do it in the model save() or prepareTable() function, or in the table check() or store() function.

for example

public function save($data)
{
   $data['name'] .= ' Bond, my name is Bond';

   return parent::save($data);
}
JulienV
  • 775
  • 7
  • 12
  • Hi, Thanks for answering. Can you please give me some sample code? – Zain Farooq Jul 06 '18 at 07:24
  • i added an example – JulienV Jul 06 '18 at 10:55
  • Hi, Thanks for giving a code example. Here I have a question that how can it know about form? I mean if I have so many forms then how can I identify form? – Zain Farooq Jul 06 '18 at 11:01
  • It should be one controller/model/table file per form. E.g for editing a contact in contact component backend, the model is com_contact/models/contact.php – JulienV Jul 06 '18 at 16:30
  • Ok Sir,, I will try it tomorrow. But can you answer this question now https://stackoverflow.com/questions/51211410/joomla-how-to-send-data-from-sub-controller-to-model – Zain Farooq Jul 06 '18 at 19:38