我想在整个HTML表单中获取PHP的值

问题描述 投票:0回答:1

我是PHP的新手,想让这些数组通过表单发送,但是无法设法将其存储在变量中并对其进行访问

HTML

<form action="./index.php" method="post">
<select name="multicheckbox[]" multiple="multiple" class="4colactive">
    <option value="LunVie" name="LunVie">Lunes a Viernes</option>
    <option value="LunSab" name="LunSab">Lunes a Sábados</option>
    <option value="Todos" name="Todos">Todos los días</option>
    <option value="Otros" name="Otros">Otros</option>
</select>
<button type="submit">Enviar</button>
</form>

PHP

<?php
  $values = $_POST["multicheckbox"];
  echo $values[2];
?>
php html forms post
1个回答
1
投票

multicheckbox是一个数组,对其进行迭代。

foreach($_POST["multicheckbox"] as $check) {
    echo $check . "<br />\n";
}

也请注意,option没有nameselectnamehttps://developer.mozilla.org/en-US/docs/Web/HTML/Element/option

<select name="multicheckbox[]" multiple="multiple" class="4colactive">
    <option value="LunVie">Lunes a Viernes</option>
    <option value="LunSab">Lunes a Sábados</option>
    <option value="Todos">Todos los días</option>
    <option value="Otros">Otros</option>
</select>
© www.soinside.com 2019 - 2024. All rights reserved.