小编Mic*_*l V的帖子

基本的OOP PHP表单类

我只是在试验OOP编程我正在尝试创建一个表单类.我无法打印复选框,我该如何查看事情的进展?

  require_once('form.php');
  $gender = new Checkbox('Please select your gender','gender',array('male','female'));
  echo $gender->show_checkbox();
Run Code Online (Sandbox Code Playgroud)

带类的文件:

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;
  }
}
Run Code Online (Sandbox Code Playgroud)

php forms oop

0
推荐指数
1
解决办法
744
查看次数

标签 统计

forms ×1

oop ×1

php ×1