Kosmos Web Design
Kosmos Web Design

Reputation: 103

How do I post multiple inputs with same name and different values

I have multiple inputs with the same Name attribute and different Values, which cannot be changed by the user.

<form action="../scripts/sc_order.php" method="post">
    <div class="sc_content">
        <input type="text" name="product[]" value="Potato" readonly/>
        <input type="text" name="product[]" value="Tomato" readonly/>
        <input type="text" name="product[]" value="Banana" readonly/>
        <input type="text" name="product[]" value="Orange" readonly/>
    </div>
    <input type="submit" value="Submit" />
</form>

The inputs are added to the form and they serve as an identifier for the product which the user has added. When the user submits the form, I should get an email with the list of values the user has selected. How do I achieve this in PHP?

Upvotes: 1

Views: 2575

Answers (1)

Henrik
Henrik

Reputation: 189

$products = $_POST['product'];

$orderedItems = "Ordered items:";
foreach($products as $product) {
  $orderedItems .= "$product ";
}

mail("[email protected]", "Subject line", $orderedItems);

You might need to set up a mail server, or you could use a service such as Mailgun.

Upvotes: 2

Related Questions