2

我是 joomla 的新手。我一直面临一个问题,我想更改 Joomla 表单值,例如当用户在表单字段中输入任何内容时,我想通过用户输入输入我自己的值。即如果用户在文本字段中输入并且用户输入他的名字约翰然后name我想通过后端添加。 这是Joomla表格netnockJohn

        <?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>


这是模型

        <?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;
        }
    }
4

1 回答 1

1

假设您在组件中遵循 joomla 指南和体系结构,您可以在模型 save() 或 prepareTable() 函数中,或在表 check() 或 store() 函数中执行此操作。

例如

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

   return parent::save($data);
}
于 2018-07-06T06:49:56.000 回答