book

Get name and value using PHP

I have this simple form:

HTML:

<input type="checkbox" name="product[]" value="20$" /> book
<input type="checkbox" name="product[]" value="30$" /> plane

PHP:


$product = $_POST['product'];
foreach($product as $value) {
    echo $value;
}

Note: The
user can select one or two ... products.

Question:
I want to know if there is a solution to get nametoo, for example, add an ID class or something like that.

Basically, I cannot get the attribute namebecause I did not submit it with the form.

+3
source share
2 answers

Add the missing information to your POST parameters:

<input type="checkbox" name="product[book]" value="20$" /> book
<input type="checkbox" name="product[plane]" value="30$" /> plane

You can iterate it like this:

foreach ($_POST['product'] as $name => $value) {
    // ...
}
+6
source

, , , , . . ( ) . "" , .

, ( "" ) :

<input type="checkbox" id="book" name="product[]" value="book" />
<label for="book">book</label>
<input type="checkbox" id="plane" name="product[]" value="plane" />
<label for="plane">plane</label>
0

All Articles