如何更改Joomla表单值?

时间:2018-07-04 09:42:30

标签: php joomla jform joomla-jform

我是joomla的新手。我遇到了一个问题,我想更改Joomla表单值,例如,当用户在表单字段中输入任何内容时,我想使用用户输入来输入自己的值。例如,如果用户在文本字段name中输入并且用户输入他的名字John,那么我想在netnock之后通过后端添加John
这是Joomla表格

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

1 个答案:

答案 0 :(得分:1)

假设您在组件中遵循joomla准则和体系结构,则可以在模型save()或prepareTable()函数或表check()或store()函数中做到这一点。

例如

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

   return parent::save($data);
}