如何更改Joomla表单值?



我是joomla的新手。我一直面临一个问题,我想更改Joomla表单值,例如,当用户在表单字段中输入任何内容时,我想通过用户输入输入自己的值。即如果用户输入文本字段name并且用户输入他的名字 John,那么我想在通过后端John后添加netnock
这是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;
}
}

假设你在组件中遵循joomla指南和架构,你可以在模型save((或prepareTable((函数中,或者在table check((或store((函数中做到这一点。

例如

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

相关内容

  • 没有找到相关文章

最新更新