JForm confusion - fieldsets

99 views
Skip to first unread message

Mike Pearl

unread,
Apr 7, 2013, 6:59:45 PM4/7/13
to joomla-de...@googlegroups.com
What do I need to do, beyond changing the form.xml file, when reorganzing form fields into fieldsets?  The form works flawlessly as a single dataset.  When I moved things around into fieldsets, the form no longer displays the data or saves data entered into the form.

All I did was move one field from the main fieldset (title field shown below):

<form>
  <fieldset name="JDETAILS">
    <field name="id" type="text" label="JGLOBAL_FIELD_ID_LABEL" description="JGLOBAL_FIELD_ID_DESC" default="0" class="readonly" size="10" readonly="true"/>
    <field name="title" type="text" label="JGLOBAL_TITLE" description="JFIELD_TITLE_DESC" class="inputbox" size="45" required="true"/>
  </fieldset>
</form>

Into another fieldset - voila things stop working.

<form>
     <fieldset name="JDETAILS">
          <field name="id" type="text" label="JGLOBAL_FIELD_ID_LABEL" description="JGLOBAL_FIELD_ID_DESC" default="0" class="readonly" size="10" readonly="true"/>
     </fieldset>
     <fields name="params">
          <fieldset name="basic" label="COM_MYCOMPONENT_BASIC_PARAMS_FIELDSET_LABEL">
               <field name="title" type="text" label="JGLOBAL_TITLE" description="JFIELD_TITLE_DESC" class="inputbox" size="45" required="true"/>
          </fieldset>
     </fields>
</form>

What do I need to do so the form displays and saves the field data as it did in a single fieldset?

Thanks!

Mike

Mark Dexter

unread,
Apr 7, 2013, 7:02:36 PM4/7/13
to joomla-de...@googlegroups.com
What code are you using to display the form? Mark
> --
> You received this message because you are subscribed to the Google Groups
> "Joomla! General Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to joomla-dev-gene...@googlegroups.com.
> To post to this group, send an email to joomla-de...@googlegroups.com.
> Visit this group at
> http://groups.google.com/group/joomla-dev-general?hl=en-GB.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Mike Pearl

unread,
Apr 7, 2013, 7:14:09 PM4/7/13
to joomla-de...@googlegroups.com
I''m loading the 'params' template from my view/tmpl/default.php file:

...
echo $this->loadTemplate('params');
...

Here's my code from the view/tmpl/default_params.php file:

defined('_JEXEC') or die;

$fieldSets = $this->form->getFieldsets('params');
foreach ($fieldSets as $name => $fieldSet) :
echo JHtml::_('sliders.panel',JText::_($fieldSet->label), $name.'-params');
if (isset($fieldSet->description) && trim($fieldSet->description)) :
echo '<p class="tip">'.$this->escape(JText::_($fieldSet->description)).'</p>';
endif;
?>
<fieldset class="panelform">
<ul class="adminformlist">
<?php foreach ($this->form->getFieldset($name) as $field) : ?>
<li>
<?php echo $field->label; ?>
<?php echo $field->input; ?>
</li>
<?php endforeach; ?>
</ul>
</fieldset>
<?php endforeach; ?>

The fields, labels and descriptions come out fine - the data, however, doesn't show or save.

Thanks!

Mike

Mark Dexter

unread,
Apr 7, 2013, 7:23:56 PM4/7/13
to joomla-de...@googlegroups.com
Hi. I might be misunderstanding, but it doesn't look like you are
putting these elements inside an HTML form element. So you don't have
any way to submit the form and start a new request to save the fields
in the database.

You might want to look at an example from core. For example, the file
components/com_weblinks/views/form/tmpl/edit.php is the front-end
weblinks edit form. It isn't looping like yours is, but that's OK. The
key thing is that the fields are rendered inside the form element,
with an action telling it to go to the weblinks component.

Hopefully that helps a bit. Good luck.

Mark

Mike Pearl

unread,
Apr 7, 2013, 7:34:12 PM4/7/13
to joomla-de...@googlegroups.com
Mark,

Thanks for the quick reply - I have the form tag in the default.php file, the $this->loadTemplate('params') loads between the <form></form> tags.    The fields displayed in the default.php file work fine, the data shows up and changes are saved properly.  default.php looks like this:

defined('_JEXEC') or die;
JHtml::_('behavior.tooltip');
JHtml::_('behavior.formvalidation');
JHtml::_('behavior.keepalive');
?>
<form action="<?php echo JRoute::_('index.php?option=com_mycomponent&layout=edit&id='.(int) $this->item->id); ?>" method="post" name="adminForm" id="user-form" class="form-validate">
<div class="width-60 fltlft">
<fieldset class="adminform">
<legend><?php echo JText::_('COM_MYCOMPONENT_NEW_RECORD'); ?></legend>
<ul class="adminformlist">
<li>
<?php echo $this->form->getLabel('fielda'); ?>
<?php echo $this->form->getInput('fielda'); ?>
</li>
<li>
<?php echo $this->form->getLabel('fieldb'); ?>
<?php echo $this->form->getInput('fieldb'); ?>
</li>
</ul>
</fieldset>
</div>
<div class="width-40 fltrt">
<?php
echo JHtml::_('sliders.start','user-sliders-'.$this->item->id, array('useCookie' => 1));
echo $this->loadTemplate('params');
?>
</div>
<div class="clr"></div>
<?php echo JHtml::_('sliders.end'); ?>
<?php } ?>
<input type="hidden" name="task" value="" />
<?php echo JHtml::_('form.token'); ?>
</form>


Mike Pearl

unread,
Apr 7, 2013, 7:38:32 PM4/7/13
to joomla-de...@googlegroups.com
The issue I'm having, is the fields in the fieldsets do not show the data from the table, nor are any changes saved in the database.  These fields worked fine when I called them with $this->form->getInput('fieldname').

When I step through the code, it looks like the data from the fieldset fields are not being passed back to the model in the same way.

Mike
 




--
You received this message because you are subscribed to a topic in the Google Groups "Joomla! General Development" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/joomla-dev-general/tT9FYDhjHKM/unsubscribe?hl=en-GB.
To unsubscribe from this group and all of its topics, send an email to joomla-dev-gene...@googlegroups.com.

elin

unread,
Apr 7, 2013, 8:15:23 PM4/7/13
to joomla-de...@googlegroups.com, mi...@basewind.com
And fielda, fieldb are the names of the columns in you database table?

Elin
To unsubscribe from this group and all of its topics, send an email to joomla-dev-general+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages