建立从复选框数组形式 [英] Make array from checkbox form

查看:94
本文介绍了建立从复选框数组形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的朋友和我正在一个网站,编译根据您的兴趣的新闻故事。有没有简便的方法来取复选框数据,并数组超出选定的复选框?这里是我们的形式

My friend and I are making a website that compiles news stories based on your interests. Is there and easy way to take the checkbox data and make an array out of the selected checkboxes? Here is our form

<form action="signup.php" method="POST">
    Name: <input type="text" name="name" /> <br />
    Username: <input type="text" name="username"> <br />
    Password: <input type="password" name="pwd" /> <br />
    Email: <input type="text" name="email" /> <br />

    <p>By filling out this we will be able to find news articles that will interest you</p>        <br />
    Politics<input type="checkbox" name="interest[]" value="Politics" /> <br />
    Entertainment<input type="checkbox" name="interest[]" value="Entertainment" /> <br />
    Tech <input type="checkbox" name="interest[]" value="Tech" /> <br />
    Health<input type="checkbox" name="interest[]" value="Health" /> <br />
    Living<input type="checkbox" name="interest[]" value="Living" /> <br />
    Travel <input type="checkbox" name="interest[]" value="Travel" /> <br />
    World<input type="checkbox" name="interest[]" value="World" /> <br />
    Leisure<input type="checkbox" name="interest[]" value="Leisure" /> <br />
    Finance<input type="checkbox" name="interest[]" value="Finance" /> <br />
    Celebrity Gossip<input type="checkbox" name="interest[]" value="Gossip" /> <br />
    Movies<input type="checkbox" name="interest[]" value="Movies" /> <br />
    Sports<input type="checkbox" name="interest[]" value="Sports" /> <br />

    <input type="submit" value="Submit">
</form>

我们怎么会让一个PHP数组使用此数据?

how would we make a php array using this data?

推荐答案

的HTML标记:

<form method="get">
    <input type="checkbox" name="options[]" value="Politics"/> Politics<br/>
    <input type="checkbox" name="options[]" value="Movies"/> Movies<br/>
    <input type="checkbox" name="options[]" value="World "/> World<br/>
    <input type="submit" value="Go!" />
</form>

和在PHP code:

and in the php code:

$checked = $_GET['options'];
for($i=0; $i < count($checked); $i++){
    echo "Selected " . $checked[$i] . "<br/>";
}

这篇关于建立从复选框数组形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆