3
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>
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’m setting up an administrative panel, where the form configuration comes automatically. I select the data from the SQL table into a variable, call a function that pulls an array with their fields and types (I’ll come back to that later) and from a repeat structure, the software creates all 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 this $_GET['mode'] = 'moderador'
, it displays the hidden fields applicable to the record to the moderator correctly, if $_GET['mode'] = 'admin'
, it displays those of the administrators, but not those of the moderator, and so on.
These fields are Hidden for a single reason: I validate all incoming entries. If the function that validates does not find the $_GET
, the only answer he will find valid will be 0000.
The point is that field-1 or field-2 are not necessarily Texts, but can be select with various options, loaded from the bench, radios, up to files, or other various things.
While writing this, I came up with two ideas: when changing the select, I checked which(s) were selected and depending on the case, carrying new fields via ajax (?). Then it would take, since they could not have fields that were loaded twice and that these loaded fields replace the hiddens. This would also require a modification in validation, but providential.
The other idea would be a little less evasive, less radical and preferable. By changing the select field, I would reload the page with the $_GET['mode']
corresponding to the one that was selected. The big problem is that I could not lose the data that was already filled.
I leave this to you, I need to change between several fields when different options are selected, including more than one option can be selected. If possible, launch new ideas or functions to use.
Additional detail: the $_GET['mode']
may be in format: $_GET['mode'] = 'admin,moderador'
how are you mounting the page? You can post the code?
– Adir Kuhn
I am far from my source code, when I get my edit note here!
– Gabriel Tadra Mainginski