2
I’m creating a form and for some fields I need to submit more than one value and I don’t know if the form I’m doing is the best or not.
<select name="itens[]">
<option value=""></option>
<option value="1||Primeiro Item">Primeiro Item</option>
<option value="2||Segundo Item">Segundo Item</option>
<option value="3||Terceiro Item">Terceiro Item</option>
</select>
So I have this element that in value I’m going through so much ID
as to the NOME
field and I am separating by two Pipes (||) , and I am doing this because I need to save both the id and the name that was at the time when saving.
My question is, does this form work? Yes, because on the other side, I can give an explosion, for example and with it separate the values, but it is the correct form or does not have a correct form, but rather a better?!
What do you want to pass the NAME? The ID was not enough?
– CesarMiguel
Have you tried it like this? It might be a good idea to test what you’re trying to do
– Jorge B.
The name I need to know what it was at the time, and that is what matters most, because if it is a value and that value changes in a future, it does not affect the data saved in the past, and guarding the id I still have a comparability of what it was and what it is at the time.
– Marcelo Diniz
@Jorgeb. I’ve tested yes and it works, but I don’t know if there’s any other more correct way to do it!
– Marcelo Diniz
I’d rather spend just the
ID
, because myNOME
are usually in a table in the database.tabela_itens
withID
andNOME
– Jorge B.
I also have a habit of doing it that way, and I think most of them are, but this is a special case.
– Marcelo Diniz
@Marcelodiniz with this treatment of the answer would be better to have a table, OR create constants to do this (in case it is PHP create
define()
)– Jorge B.