I'd like to render the same fieldset multiple times for batch create and batch update. Is it possible to do this with JForms?
Currently I have a form like this:
<?xml version="1.0" encoding="UTF-8"?>
<form name="customer_registration_form" title="COM_CANTEEN_CUSTOMER_REGISTRATION_TITLE" description="COM_CANTEEN_CUSTOMER_REGISTRATION_DESCRIPTION" buttonLabel="COM_CANTEEN_CUSTOMER_REGISTRATION_BUTTON_LABEL" class="customer-registration">
<fields name="customer_registration">
<fieldset name="customer_registration">
<field name="name" type="text" required="true" size="80"
validate="text" minLength="4" maxLength="80" pattern="^\p{L}+(?:[\p{Zs}-]\p{L}+)+$"
label="COM_CANTEEN_CUSTOMER_REGISTRATION_NAME_LABEL" description="COM_CANTEEN_CUSTOMER_REGISTRATION_NAME_DESCRIPTION" message="COM_CANTEEN_CUSTOMER_REGISTRATION_NAME_MESSAGE" />
<field name="age" type="integer" required="true" default="6" first="1" last="150" step="1"
validate="integer" min="1" max="150"
label="COM_CANTEEN_CUSTOMER_REGISTRATION_AGE_LABEL" description="COM_CANTEEN_CUSTOMER_REGISTRATION_AGE_DESCRIPTION" message="COM_CANTEEN_CUSTOMER_REGISTRATION_AGE_MESSAGE" />
<field name="permanent_orderer" type="checkbox" default="1"
label="COM_CANTEEN_CUSTOMER_REGISTRATION_PERMANENT_ORDERER_LABEL" description="COM_CANTEEN_CUSTOMER_REGISTRATION_PERMANENT_ORDERER_DESCRIPTION" message="COM_CANTEEN_CUSTOMER_REGISTRATION_PERMANENT_ORDERER_MESSAGE" />
</fieldset>
</fields>
</form>
Which I render with this layout:
<?php
extract($displayData);
JHtml::_('behavior.tooltip');
?>
<form action="<?php echo $action; ?>"
method="post" name="<?php echo $form->getAttribute('name'); ?>" class="<?php echo $form->getAttribute('class'); ?> basic-form-layout">
<legend><?php echo JText::_($form->getAttribute('title')); ?></legend>
<?php
echo JText::_($form->getAttribute('description'));
foreach (array_keys($form->getFieldsets()) as $fieldset)
echo $form->renderFieldset($fieldset);
?>
<?php echo JHtml::_('form.token'); ?>
<div class="control-group">
<div class="control-label"> </div>
<div class="controls">
<button type="submit"><?php echo JText::_($form->getAttribute('buttonLabel')); ?></button>
</div>
</div>
</form>
By sending the form I got a customer_registration[field]
array. I'd like to get a customer_registration[i][field]
or customer_registration[field][i]
array instead. Is this supported somehow, or should I write a workaround?
The rendering part is okay, I guess I have to call renderFieldset
multiple times, but how can I override the customer_registration
to get customer_registration[i]
? The only solution I could come up is rendering the fieldset, finding the field names in the resulted html, and overriding them with regex, or with simplexml. Any other idea? Or is this already implemented somehow and I was superficial by checking the feature?