Hide fields using loop

Hi,

I`v got a form with some fileds like this:

field1
field2
field3

field40

I would like to hide them :slight_smile: I can use sc_field_display macro but its not funny to write 40x this macro so i tried a loop like this

for ($i=1;$i <={dataset[0][0]}; $i++) {
    $name = "field" . $i;
    sc_field_display($name,"off");
}

but the source code looking like this:

for ($i=1;$i <=$this->dataset[0][0] ; $i++) {
  $nazwa = "exp" . $i;
  $this->nmgp_cmp_hidden["name"] = "off";
  $this->NM_ajax_info['fieldDisplay']['name'] = 'off';
}

macro sc_field_display doesn`t work with variables… so what now ?

Now we have to wrote in our code:

for ($i=1;$i <={dataset[0][0]}; $i++) {
    $name = "field" . $i;
    $this->nmgp_cmp_hidden["".$name.""] = "off";
    $this->NM_ajax_info['fieldDisplay'][''.$name.''] = 'off';
}

And we got what we want :slight_smile:
I suggest to modify sc_field_display macro to work with variables

Re: Hide fields using loop

Hello,

there are other functions of SC which don’t work with $variables… but they work with [] variables.
You may try this way to use your variable. I myself did not try it… it’s only a tip.

Best regards
Uwe Pfeiffer

Re: Hide fields using loop

Place them in a block and hide the block(s).

Regards,
Scott.