我无法确保我的所有表单输入都填写在 OOP 中。通常我可以做到这一点。但我对 OOP 编程有点陌生。我想确保当我的按钮被点击时。
它将控制我的所有表格是否为空。如果为空,则必须回显一条消息(该消息是荷兰语,但基本上意味着您仍有未填写的输入)。但是,它不起作用。该消息始终显示,即使我确实填写了我的输入并单击提交。我不知道我做错了什么。
我的代码:
<?php
class UserForm{
//Making properties to later use
private $Vvoornaam;
private $Vachternaam;
private $Vemail;
private $Vbericht;
private $Bsubmit;
public function __contruct() {
//Giving the properties a value
$this->Vvoornaam = $_POST["voornaam"];
$this->Vachternaam = $_POST["achternaam"];
$this->Vemail = $_POST["email"];
$this->$Vbericht = $_POST["bericht"];
$this->$Bsubmit = $_POST["submit"];
}
public function Index() {
//Checking if a message has been posted yes or no. If yes, then execute the code from line 21 to 41
if(isset($_POST[$this->Bsubmit]) && empty($this->Vvoornaam) || empty($this->Vachternaam) || empty($this->Vemail) || empty($this->Vbericht)) {
echo "U moet nog al uw gegevens invullen";
}
}
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$userForm = new UserForm(); $userForm->Index();
}
?>
如您所见,问题是当您提交并且输入为空时应该会出现此消息。然而,这条信息始终存在。
我希望你们能帮助我。那太好了!