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.
<?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;
}
}
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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.