Hello, I have the following select:
<select name="hierarquia[]" multiple>
<option value="Usuário" selected> Usuário</option>
<option value="Moderador" selected> Moderador</option>
<option value="Administrador"> Administrador</option>
</select>
And I also have following fields (examples):
<input type="hidden" id="campo-1" name ="campo-1" value="0000">
<input type="hidden" id="campo-2" name ="campo-2" value="0000">
I am putting together an administrative panel, where the configuration of the forms comes automatically. I set the SQL table data in a variable, call a function that pulls an array with the fields and their types (I'll go back on that later) and from a repeat structure, the software creates all the inputs, selects, radios, etc.
The fact is that there are some fields that are special, only appear when you add a specific user type, evidenced by $_GET['mode']
, that is, if that $_GET['mode'] = 'moderador'
, it displays hidden fields that can be moderator correctly, case $_GET['mode'] = 'admin'
, it displays those of the admin, but not those of the moderator, and so on.
These fields are hidden for a single reason: I validate all incoming entries. If the validating function does not find $_GET
, the only answer it will find valid is 0000.
The issue is that field-1 or field-2 are not necessarily texts, but can be select with varying options, loaded from the database, radios, even files, or various other things.
As I wrote this, two ideas came to mind: when I changed the select, I checked which ones were selected and depending on the case, loading new fields via ajax (?). Then he would pick up, since they could not have fields that were loaded twice and those charged fields replace the hiddens. This would also require a change in validation, but it will be provided.
The other idea would be a little less evasive, less radical and preferable. Changing the select field would reload the page with $_GET['mode']
corresponding to the one selected. The big problem is that I could not lose the data that has already been filled.
I leave this with you, I need to change between several fields when different options are selected, even if more than one option can be selected. If possible, launch new ideas or functions to use.
Additional detail: $_GET['mode']
can be in the format: $_GET['mode'] = 'admin,moderador'