⚠ 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

How to set a custom config item for a table and use it in edit.php or add.php



rudyKipling
  • profile picture
  • Member

Posted 04 March 2018 - 21:10 PM

Hello,

 

I have been trying to code tabbed views for grocery crud in edit and add forms. I have did some changes on bootstrap theme's edit.php and add.php, so now i can slice form elements to tabs.

 

In add.php and edit.php files, i have 2 parameters, one of them is $slice_form, if it is true, form elements are sliced to tabs. The other parameter is $field_count_on_each_tab, it is the count of form elements that will be shown on each tab. 

 

 I have replaced this code, in add.php and edit.php:

 

<?php foreach($fields as $field) { ?>
 
<div class="md-form <?php echo $field->field_name; ?>_form_group">
        <label><?php echo $input_fields[$field->field_name]->display_as; ?><?php echo ($input_fields[$field->field_name]->required) ? "<span class='required'>*</span> " : ""; ?></label>
        <?php echo $input_fields[$field->field_name]->input?>
    </div>
                <?php }?>

 

 

 

 

 

To this code:

 

<?php $slice_form = true; ?>
 
   <?php if($slice_form){ ?>
   
   <?php $field_count_on_each_tab = 3;  ?>
 
<ul class="nav nav-tabs" role="tablist">
<?php 
 
$i = 1;
?>
            <?php foreach($fields as $field) { ?>
 
<?php if($i==1 || $i%$field_count_on_each_tab == 1) { ?><li class="nav-item"><?php } ?>
 
<?php if($i==1) { echo '<a class="nav-link active" data-toggle="tab" href="#'.$field->field_name.'" role="tab">'.$input_fields[$field->field_name]->display_as.'</a>';  } else if($i%$field_count_on_each_tab == 1){echo '<a class="nav-link" data-toggle="tab" href="#'.$field->field_name.'" role="tab">'.$input_fields[$field->field_name]->display_as.'</a>';} ?>
 
<?php if($i%$field_count_on_each_tab == 0) echo "</li>";  ?>
 
    <?php $i = $i+1; ?>
</li>
            <?php }?>
</ul>
 
 
<div class="tab-content">
<?php 
 
$i = 1;
?>
            <?php foreach($fields as $field) { ?>
 
<?php if($i==1) { echo '<div class="tab-pane active" id="'.$field->field_name.'" role="tabpanel">';  } else if($i%$field_count_on_each_tab == 1){echo '<div class="tab-pane" id="'.$field->field_name.'" role="tabpanel">';} ?>
 
<div class="md-form <?php echo $field->field_name; ?>_form_group">
        <label <?php if (!preg_match("/chosen-select/", $input_fields[$field->field_name]->input)) echo 'class="active"';?>><?php echo $input_fields[$field->field_name]->display_as; ?><?php echo ($input_fields[$field->field_name]->required) ? "<span class='required'>*</span> " : ""; ?></label>
        <?php echo $input_fields[$field->field_name]->input;?>
    </div>
 
<?php if($i%$field_count_on_each_tab == 0) echo "</div>";  ?>
    <?php $i = $i+1; ?>
 
            <?php }?>
 
</div>
   <?php }else { ?>
   
<?php foreach($fields as $field) { ?>
<div class="md-form <?php echo $field->field_name; ?>_form_group">
        <label <?php if (!preg_match("/chosen-select/", $input_fields[$field->field_name]->input)) echo 'class="active"';?>><?php echo $input_fields[$field->field_name]->display_as; ?><?php echo ($input_fields[$field->field_name]->required) ? "<span class='required'>*</span> " : ""; ?></label>
        <?php echo $input_fields[$field->field_name]->input;?>
    </div>
<?php }?>
 
   <?php } ?>
 
 
 
 
 
So now, i have achieved to view elements in tabs. But i want this option to be selectable for each table. I dont know how to pass values to add.php and edit.php. I just need to change  $field_count_on_each_tab  and  $slice_form values from a specific controller.
 
Plz help. :/