0
I have a form with <textarea>
with the following value:
<textarea id="lista-ingredientes" name="lista-ingredientes">
<ul>
<li>sal</li>
<li>pimenta</li>
</ul>
<textarea>
I need that when sending the form, PHP "break" the items of <li>
in separate variables to add a row of each item, what I have is this one, but it inserts everything in one line:
$sql = "INSERT INTO receitas_ingredientes (id, ingrediente) VALUES ('NULL', ".$_POST['lista-ingredientes'].")";
I believe it is something using explodes and foreach, but I do not have much knowledge and I could not assemble
Question: Why do you own one
ul/li
within atextarea
? The only permitted type of content for atextarea
is text, so thisul
would be interpreted as plain text, not HTML, not making much sense.– Woss
yes, it is that after this value will be pulled from the table to show inside a div, there is a better, or more correct, way to do this?
– Leandro Marzullo
what happens is that I have an ingredient input +add button that with a jquery will add all the ingredients in the text area, then insert them all at once in the table
– Leandro Marzullo
@Leandromarzullo the ideal is to save in the bank without the read and when you pull from the bank and insert in the view, add the text inside the li in a foreach, for example
– David Alves
got it, just for you to see, this is what I was doing: https://answall.com/questions/245268/bot%C3%A3o-add-insert-value-do-input-inside-do-pr%C3%B3prio-formul%C3%A1rio/245274#245274
– Leandro Marzullo
the ideal is I save as <textarea>1;2;3;4</textarea> then when I show this value I break them and play the <li>, this?
– Leandro Marzullo
No.
textarea
It doesn’t even make sense to exist. You can store the ingredient list within a JS structure or even structure the list with HTML correctly.– Woss
From what I understand, you are putting in the textarea to go displaying to the user, but you can put tbm in a <input type="Hidden" name="lista_ingredientes[]"> saving as an array and pick this field when saving and with it would be better for you to work with the data
– Marcelo Diniz
Actually, they ended up helping me a lot in the other problem.... rs, Rigadão!!!!
– Leandro Marzullo
I replied in the original question a much more viable solution to the problem. The one that had been presented there, and used here, is not good.
– Woss