1
我有一個帶有字符串的數組,我想創建一個帶有複選框的表單,其中每個字符串都有自己的複選框。函數$Service->read_command_cfg();
返回正確的數組。如何創建一個帶有數組值的複選框表單
我的PHP代碼如下:
<form action="host_add.php" method = "post" >
<?PHP
include_once('service.php');
echo'Services:';
if (!empty($_POST['host_select']))
{
$Service = new Service;
$array_command_name_new = $Service->read_command_cfg();
}
foreach($array_command_name_new as $key=>$value)
{
echo'<p><input type="checkbox" name="'.$value.'" value="'.$value.'/>' .$value. '</p>';
}
?>
</form>
我得到了下面的HTML輸出:
<form action="host_add.php" method = "post" >
Services:<p><input type="checkbox" name="command_name notify-host" value="command_name notify-host/>command_name notify-host</p><p><input type="checkbox" name="command_name notify-service" value="command_name notify-service/>command_name notify-service</p>
</form>
在我只有一個checkbutton沒有文字的網站。
一切都看起來不錯。你的html顯示兩個複選框。我不認爲我理解這個問題。 –
您錯過了'value ='''的引用。$ value。'「' – billyonecan
沒關係,我認爲@billyonecan只是釘上了它。 –