/ Published in: PHP
URL: http://www.phpclasses.org/browse/file/27381.html
Expand |
Embed | Plain Text
<?php /** * array2form * written by: Mark Berube * Takes an array of form input parameters and builds form rows in a 2 column vertical layout table format * In addition to the common form inputs, there are two custom form input this class will interpret: * 1. date: creates a text input which is populated from clicking an icon pointed to any javascript calendar script * 2. custom: creates a text input which is populated from clicking an icon pointed to any javascript function(useful for sql queries etc)) * See accompanying expample page for more detailed usage */ class array2form{ public $icon_dir = './'; public $cal_icon = 'calicon2_20.png'; public $cust_icon = '1downarrow.png'; function array2form($input_array){ $rows = ""; foreach($input_array as $input){ $params = $this->get_input_params($input); switch ($type){ case 'text': $form_input = $this->get_text_input($params['name'],$params['values'], $params['size']); break; case 'radio': $form_input = $this->get_radio_input($params['name'],$params['values']); break; case 'checkbox': $form_input = $this->get_check_input($params['name'],$params['values']); break; case 'select': $form_input = $this->get_select_input($params['name'],$params['values']); break; case 'textarea': $form_input = $this->get_textarea_input($params['name'],$params['size']); break; case 'custom': $form_input = $this->text_from_script_call($params['name'],$params['values'],$params['size'],$params['script']); break; case 'date': $form_input = $this->get_date_input($params['name'],'',$params['script']); break; } $row = "\n<tr>\n\t<td class=\"form_heading\">\n\t\t".$params['label']."\n\t</td>\n\t<td class=\"form_input\" nowrap>\n\t\t$form_input\n\t</td>\n</tr>"; $rows .= $row; } echo $rows; } private function get_input_params($input){ //if the input_name left blank, make one out of the label if($input_name == ''){ } 'type' => $input_type, 'label' => $heading, 'name' => $input_name, 'values' => $values, 'size' => $input_size, 'script' => $script_call ); return $params; } private function text_from_script_call($input_name, $default_value, $size, $script_call){ $form_input = "<INPUT TYPE=\"text\" NAME=\"$input_name\" ID=\"$input_name\" SIZE=\"$size\" VALUE=\"$default_value\" readonly>\n"; $icon = $this->icon_dir . $this->cust_icon; $form_input .= "<IMG src=\"1downarrow.png\" onclick=\"$script_call\">\n"; return $form_input; } private function get_text_input($input_name, $default_value, $size){ $form_input = "<INPUT TYPE=\"text\" NAME=\"$input_name\" ID=\"$input_name\" SIZE=\"$size\" VALUE=\"$default_value\">\n"; return $form_input; } private function get_textarea_input($input_name, $size){ $form_input = "<TEXTAREA NAME=\"$input_name\" ID=\"$input_name\" ROWS=\"$rows\" COLS=\"$cols\"></TEXTAREA>\n"; return $form_input; } private function get_date_input($input_name, $default_value, $script_call){ $form_input = "<INPUT TYPE=\"text\" NAME=\"$input_name\" ID=\"$input_name\" SIZE=\"10\" MAXLENGTH=\"10\" VALUE=\"$default_value\" readonly>\n"; $icon = $this->icon_dir . $this->cal_icon; $form_input .= "<IMG src=\"$icon\" onclick=\"$script_call\">\n"; return $form_input; } private function get_radio_input($input_name, $values){ $search = '(checked)'; $form_input = ""; foreach($vals as $val){ $on = true; }else{ $on = false; } $form_input .= "$val<INPUT TYPE=\"radio\" NAME=\"$input_name\" VALUE=\"$val\""; $form_input .= "> \n"; } return $form_input; } private function get_check_input($input_name, $values){ $search = '(checked)'; $form_input = ""; $count = 0; foreach($vals as $val){ $on = true; }else{ $on = false; } $form_input .= "$val<INPUT TYPE=\"checkbox\" NAME=\"". $input_name . '['.$count .']' ."\" VALUE=\"$val\""; $form_input .= "> \n"; $count ; } return $form_input; } private function get_select_input($input_name, $values){ $search = '(selected)'; $form_input = "<SELECT NAME=\"$input_name\" ID=\"$input_name\">\n"; foreach($vals as $val){ $on = true; }else{ $on = false; } $form_input .= "\t<OPTION VALUE=\"$val\""; $form_input .= ">$val</OPTION>\n"; } $form_input .= "</SELECT>\n"; return $form_input; } } ?>
You need to login to post a comment.
