help to better help you:

Please: add always Joomla / JEM version and details to your posts, so we can try to reproduce your issue!

J3 - hide fields within a form

J3 - hide fields within a form

10 years 5 months ago - 10 years 5 months ago
#14725
Here some info about hiding a field within a form

We do have a form and it's having some fields, we did set up the models/controllers etc and now we want to hide a field.

divs+getInput/Label
within the views you'll see something like
Code:
<div class="control-group"> <div class="control-label"><?php echo $this->form->getLabel('test');?></div> <div class="controls"><?php echo $this->form->getInput('test'); ?></div> </div>

that's fine but what if we want to hide a field completely that can give problems, this as the dis are hardcoded but the retrieval of getLabel/getInput not. So if the field is hidden it will still output the divs and it will lead to empty spaces.

so a way to do it is to replace that code within the edit file so it will be something like
Code:
<?php echo $this->form->renderField('test'); ?>

but we've to do more.

altering model
Next thing we do is altering the model.
-> seach for "public function getForm"

in there you can modify the form-data so if we want to strip/remove a field completely we can do it here.
Code:
# define needed values $test = some defined data; if (!($test)) { # the test field is not needed $form->removeField('test); }


//
don't use setFieldAttribute as the fields will still be within the formdata and if validation is set but field hidden or somethinglike that it will trow in unneeded errors.
Last edit: 10 years 5 months ago by Bluefox.

Please Log in or Create an account to join the conversation.

Time to create page: 0.519 seconds