简体   繁体   中英

Joomla 2.5 xml fields - store values after form submit

I have a typical XML file with many field like example

<field
type="custom"
name="city"
id="city"
label="City"
size="40"/>

In the view I display this field - everything is fine. Moreover I'm using state filtering on this field. model populateState():

$filter = $app->input->get('city');
$this->setState('filter.city', $filter);

The problem is that, field doesn't has a value after form submit (form has get method). I can't write in field value something like $this->getState('city') because it's xml file. Maybe anyone has a solution... I was thinking about JS, but mainly I want to have a PHP solution.

Problem solved! Here is solution: 1. Have all fields name in jform array. It makes automatically if you use form in xml. 2. When you're loading form data, send second parameter as true: $model->getForm('formName', true) because second parameter is $loadData . By this option, Joomla will load form data. 3. You have load data from loadFormData function:

protected function loadFormData() {
        $data = JFactory::getApplication()->getUserStateFromRequest('jform', 'jform');
        if (empty($data)) {
            $data = $this->getItem();
        }

        return $data;
    }

That's all.

I'm not 100% clear on what you're asking, but if you're using a standard JForm and inserting it with something like this:

echo $this->form->getInput('articletext');

The it's likely the your field's name in the form isn't city , it's more likely to be something like:

`jform[articletext]`

If you can add more of the XML file, so we can see grouping etc and the php used to display the form we can probably help pin it down exactly, it will also help if you tell us which version of Joomla you're using.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM