How to get an array of data from select in a HTML form. PHP ... open

How to get an array of data from select in a HTML form. PHP code example

Test forms:

<!doctype html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Test form</title>
</head>

<body>

    <form action="index.php" method="post">

        <p>Name: <input type="text" name="name"></p>
        <p>E-mail: <input type="email" name="email"></p>
        <p>Text: <textarea name="message"></textarea></p>
        <p>Agree? <input type="checkbox" name="agree"></p>
        <p>
            <select name="lang[]" multiple>
                <option value="ru">Russian</option>
                <option value="en">English</option>
                <option value="fr">France</option>
            </select>
        </p>
        <p><button type="submit" name="send_form">Send</button></p>

    </form>

    <hr>

    <form action="index.php" method="get">

        <p>Search: <input type="text" name="s"></p>
        <p><button type="submit" name="search_form" value="search">Send</button></p>

    </form>

    <a href="?id=1">Product 1</a>
    <a href="?id=5">Product 5</a>


</body>

</html>

On index.php

 foreach ($_POST['lang'] as $lang) {
        var_dump($lang);
    }
0

More

Leave a Reply

Your email address will not be published. Required fields are marked *

How many?: 22 + 22

lil-code© | 2022 - 2024
Go Top
Authorization
*
*
Registration
*
*
*
*
Password generation