我在表单中使用私有字段作为名称属性,而不是对值进行硬编码。但是,由于某种原因,这些值没有从私有字段中获取并放入名称属性中,我就是不知道为什么。
<?php
namespace View;
class UserView {
private $checkBox = "check[]";
private $submitRemove = "submitRemove";
public function ShowUsers() {
$userNameArray = array("foo", "bar", "hallo", "world");
$userIdArray = array(1, 2, 3);
$users = "";
$nrOfUsers = count($userNameArray);
// Name attribute of input fields created is left blank
for ($i = 0; $i < $nrOfUsers; $i++) {
$users .= "<label for='$userIdArray[$i]'>
$userNameArray[$i]
<input type='checkbox' name='$this->checkBox' value='$userIdArray[$i]' /><br/>
</label>";
}
$userList = "<div class='userList'>
<form id='form3' method='post' action=''>
<fieldset>
<p>Existing users</p>
$users
<input type='submit' id='$this->submitRemove' name='$this->submitRemove' Value='Ta bort' /> // name attribute is left blank
</fieldset>
</form>
</div>";
return $userList;
}