将表单的值插入变量时,我遇到了一个问题,我将代码的一小部分放入其中,因为它不会占用很多不必要的行。
如果我执行$ _POST ['test']
的var_dump格式输入数据,我会看到这是否是我设置的数据,但我不知道为什么它没有存储在此行中: / p>
$ this-> assignSubject($ _ POST ['test'],$ name);
例如,如果正确保存,我用value =
的形式输入了默认值。
可能是什么问题?
class Secretary {
public $students = array();
public $subjects = array();
public function findStudent($n) {
foreach($this->students as $d) {
if($d->getName() == $n) return ($d);
}
return false;
}
public function findSubject($n) {
foreach($this->subjects as $p) {
if($p->getName() == $n) return ($p);
}
return false;
}
public function assignSubject($pName, $dName) {
$subject = $this->findSubject($pName);
$student = $this->findStudent($dName);
if($subject && $student) {
$student->subjectsAssign[] = $subject;
return true;
}
return false;
}
public function checkName($name) {
if(array_search($name, array_column($this->students, 'name')) !== false) {
form();
if ($_POST['action'] == "recordData") {
// I do not save the form data in $ _POST ['test'].
$this->assignSubject($_POST['test'], $name);
}
}
else {
otherForm();
}
}
}
}
function form(){
echo '<FORM METHOD="POST" >
<label>Add the subject : </label><INPUT TYPE = "text" NAME = "test"> <br>
<INPUT TYPE = "hidden" NAME = "action" VALUE = "recordData">
<INPUT class="form" TYPE = "submit" >
</ FORM>';
}
答案 0 :(得分:0)
您错过了this作为类变量。 Thays为什么不做任何事情。
public function assignSubject($pName, $dName) {
$subject = $this->findSubject($pName);
$student = $this->findStudent($dName);
if($subject && $student) {
$this->student->subjectsAssign[] = $subject;
return true;
}
return false;
}