questions = $attached_questions; } function open($action){ return "
\n"; } } class Question{ public $id; public $type; public $title; public $help_text; public $options = array(); public $is_required; public $q_index; public $question_count = 0; public $radio_count = 0; function __construct($meta){ foreach ( $meta as $key => $value ) { //$this->$key = $value; $this->set_property($key, $value); } //set question count - required for correctly naming form inputs } function set_value($field, $default){ if(! isset($_POST[$field])){ return $default; } return $_POST[$field]; } function set_check($field, $value){ //loop thru input array. if the value of the input matches the value of the field, check it if(! isset($_POST[$field])){ return ''; } //if checkbox if(is_array($_POST[$field])){ foreach($_POST[$field] as $input){ if($input === $value){ return 'checked="checked"'; } } }else{ if($_POST[$field] === $value){ return 'checked="checked"'; } } } function set_select($field, $value){ //loop thru input array. if the value of the input matches the value of the field, check it if(! isset($_POST[$field])){ return ''; } if($_POST[$field] === $value){ return 'selected="selected"'; } } function check_required(){ if($this->is_required == 'true'){ return '*'; } } function set_property($prop, $val){ $this->$prop = $val; } function get_property($prop){ return $this->$prop; } function html(){ $html; $required = ''; //set to 'required' if required if(!isset($this->type)){return 'error: Question type not defined';} //begin form box if($this->is_required == 'true'){ $required = '_required'; } $html = '| $title | "; } $html .= "|
|---|---|
| '.implode(',',$value).' | '; }else{ $html .= "$value | "; } } $html .= "