我只是在尝试 OOP 编程,我正在尝试创建一个表单类。我无法打印复选框,我如何检查哪里出错了?
require_once('form.php');
$gender = new Checkbox('Please select your gender','gender',array('male','female'));
echo $gender->show_checkbox();
带有类的文件:
class Inputfield{
public $id;
public $options_array;
public $question;
public $type;
function __construct($newquestion,$newid,$newoptions_array){
$this->question=$newquestion;
$this->id=$newid;
$this->type="txt";
$this->options_array=$newoptions_array;
}
public function show_options($options_arr,$type,$id,$classes){
$output="";
foreach($options_arr as $option){
$output.="<label for=\"".$option."\"></label><input name=\"".$option."\" type=\"".$type."\" id=\"".$id."\" class=\"".$classes."\">";
}
return $output;
}
public function show_question(){
$output="<h3 class='question'>".$this->vraag."</h3>";
return $output;
}
}
class Checkbox extends Inputfield{
function __construct($newquestion,$newid,$newoptions_array){
$this->question=$newquestion;
$this->id=$newid;
$this->type="checkbox";
$this->options_array=$newoptions_array;
}
public function show_checkbox(){
$output=show_question();
$output.=show_options($this->options_array,'checkbox',$this->id,'class');
return $output;
}
}