⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Add/edit form group sections



gavin1211
  • profile picture
  • Member

Posted 18 April 2012 - 20:17 PM

Is there a way to group fields, adding a header or something. Some forms can be very long when listing inputs in a linear way. Grouping would improve usability?

Thanks

Cèsar Martí
  • profile picture
  • Member

Posted 19 April 2012 - 08:31 AM

Hi gavin1211.

This is what I made. The example is for edit, but it's more or less the same for add.

[php]$crud->edit_fields('name', 'surname', 'details', 'email', 'phone');[/php]

"details" it's not a real field.

[php]$crud->display_as('details', '' )[/php]

With the last line, there won't be a label in the left.

[php]$crud->callback_edit_field('details', array($this, 'tit_details'))[/php]

We change what we are gonna see instead of the non-field "details"

[php]function tit_details($value = null, $primary_key = null)
{
return '<h1 class="a_class_if_you_want">'.sprintf(lang('details')).'</h1>';
}[/php]

You can write directly whatever in the h1 tag or, like me, read it from the lang file.

You have to realise, where it has the label, you will see the colon [:] alone. I didn't like it, so I changed in themes/datables/views the add.php and edit.php, around the line 40 or 42.

[php]<div class='form-display-as-box' id="<?php echo $field->field_name; ?>_display_as_box">
<?php echo $input_fields[$field->field_name]->display_as?><?php echo ($input_fields[$field->field_name]->required)? "<span class='required'>*</span> " : ""?> <?php echo ($input_fields[$field->field_name]->display_as)? ":" : ""?></div>[/php]

With the last lines you only see the colon if there's something in the label; instead, the colon won't be.

Let me know if you have any doubt.