2

我对 php 编程很陌生,但我试图将值从 multislect 对象 im html 传递给 PHP 中的一些代码,然后这些代码将通过电子邮件发送给列出的人

然而,通过帖子传递的变量似乎只是最后一个选择的项目

你如何将某些东西作为数组传递?

html代码:

<li id="li_6" >
            <label class="description" for="Names[]">Employees who should be added to this charge code: (Hold CTRL to Multi Select)</label>
            Malav, Nancy, Filiz, CJ are added by default and not on the list
            <div>
                <select name="Names" multiple>  
                    <option value="gbiy@afsafd.com">Bi,Gilbert</option>
                    <option value="jbster@asdfasds.com">Bor,Jeff</option>
                    <option value="ibett@adfasdfions.com">Bt,Ivan</option>
                    <option value="scelos@agasdgasdns.com">Caos,Sheryl</option>
                    <option value="rcarsfsfdgy@madfasdfs.com">Car,Raymond</option>
                    <option value="dcaraahers@asdfasdftions.com">Cs,Dale</option>
                    <option value="Cclesfdgsdents@mabukhyns.com">Cles,Cathy</option>
                    <option value="lcugh@madsfadsfasds.com">Cl,Lori</option>
                    <option value="rcolns@madsfasdfons.com">Cons,Renee</option>
                    <option value="ccrine@maasdfkoadsfasd.com">ine,Cassandra</option>
                    <option value="pcrett@maadsfasdfons.com">Ctt,Pamela</option>
</select>
            </div> 
        </li>

php代码:

<?php
// Read POST request params into global vars
    $from = "BP@fgsdfgsons.com";
    $title = $_POST[Title] ;
    $mname = $_POST[ManagerName];
    $memail = $_POST[ManagerEmail];
    **$names= $_POST['Names']; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<**
    $other = $_POST[element_4];

    print $email;
    $to = "sfgsdfg@sdfgsdfgssbd.com" + $memail;
    $message ="Title: $title \r\nManager: $mname\r\nManager email: $memail\r\n" ;
    $headers = "From: $from";
    $today = date("m/d/Y");
    $ok = @mail($to, $subject, $message, $headers);

    echo "Your email has been sent! Please confirm with Malav if you do not receive a confrimation email in 2 hours";
?>
4

3 回答 3

10

要将其作为值数组传递,请将方括号添加到 select 元素的 name 属性中。

<select name="names[]" multiple="multiple"> 

然后你可以遍历 php.ini 中的值。

foreach ( $_POST['names'] as $selectedOption )
于 2013-01-08T22:55:58.197 回答
1
foreach ($_POST['Names'] as $selectedOption)
    echo $selectedOption."\n";
于 2013-01-08T22:57:44.573 回答
0

当我使用这个时:

foreach ( $_POST['names'] as $selectedOption )

我在数据库中插入“$selectedOption”,出现在数据库中:

于 2015-03-26T13:48:35.490 回答