action = $action; $this->method = $method; } /* * Add a hidden form input */ function hidden($name,$value) { $c = count($this->hidden); $this->hidden[$c]['name'] = $name; $this->hidden[$c]['value'] = $value; } /* * Add a text form input */ function text($label,$name,$value,$size='30',$maxlength='') { $c = count($this->input); $this->input[$c]['type'] = 'text'; $this->input[$c]['label'] = $label; $this->input[$c]['name'] = $name; $this->input[$c]['value'] = $value; $this->input[$c]['size'] = $size; if ( $maxlength == '' ) { $this->input[$c]['maxlength'] = $size; } else { $this->input[$c]['maxlength'] = $maxlength; } } /* * Add a password form input */ function password($label,$name,$value,$size='30',$maxlength='') { $c = count($this->input); $this->input[$c]['type'] = 'password'; $this->input[$c]['label'] = $label; $this->input[$c]['name'] = $name; $this->input[$c]['value'] = $value; $this->input[$c]['size'] = $size; if ( $maxlength == '' ) { $this->input[$c]['maxlength'] = $size; } else { $this->input[$c]['maxlength'] = $maxlength; } } /* * Add a file form input */ function file($label,$name,$value,$size='30',$maxlength='') { $c = count($this->input); $this->input[$c]['type'] = 'file'; $this->input[$c]['label'] = $label; $this->input[$c]['name'] = $name; $this->input[$c]['value'] = $value; $this->input[$c]['size'] = $size; if ( $maxlength == '' ) { $this->input[$c]['maxlength'] = $size; } else { $this->input[$c]['maxlength'] = $maxlength; } } /* * Add a textarea form input */ function textarea($label,$name,$value,$rows='5',$cols='60') { $c = count($this->input); $this->input[$c]['type'] = 'textarea'; $this->input[$c]['label'] = $label; $this->input[$c]['name'] = $name; $this->input[$c]['value'] = $value; $this->input[$c]['rows'] = $rows; $this->input[$c]['cols'] = $cols; } /* * Add a select form input * $options must be a key/value array */ function select($label,$name,$options,$selected='',$size='1') { $c = count($this->input); $this->input[$c]['type'] = 'select'; $this->input[$c]['label'] = $label; $this->input[$c]['name'] = $name; $this->input[$c]['options'] = $options; $this->input[$c]['selected'] = $selected; $this->input[$c]['size'] = $size; } /* * Add a captcha form input. This is an input test used to prevent spam. */ function captcha() { $c = count($this->input); $this->input[$c]['type'] = 'captcha'; } /* * Add a submit button */ function submit($name,$value) { $c = count($this->submit); $this->submit[$c]['name'] = $name; $this->submit[$c]['value'] = $value; } /* * Add a reset button */ function reset($name) { $this->reset = $name; } /* * Generate a captcha image for the form and set it to the session */ function generateCaptcha() { $image = imagecreate(100, 30); $white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF); $gray = imagecolorallocate($image, 0xC0, 0xC0, 0xC0); $darkgray = imagecolorallocate($image, 0x50, 0x50, 0x50); srand((double)microtime()*1000000); for ($i = 0; $i < 30; $i++) { $x1 = rand(0,100); $y1 = rand(0,30); $x2 = rand(0,100); $y2 = rand(0,30); imageline($image, $x1, $y1, $x2, $y2 , $gray); } for ($i = 0; $i < 5; $i++) { $cnum[$i] = rand(0,9); } for ($i = 0; $i < 5; $i++) { $fnt = rand(3,5); $x = $x + rand(12 , 20); $y = rand(7 , 12); imagestring($image, $fnt, $x, $y, $cnum[$i] , $darkgray); } $digit = "$cnum[0]$cnum[1]$cnum[2]$cnum[3]$cnum[4]"; $_SESSION['inCaptcha'] = $digit; header('Content-type: image/png'); imagepng($image); imagedestroy($image); exit; } /* * Render the defined form into HTML */ function render() { $output = "
action . "\" method=\"" . $this->method . "\" enctype=\"multipart/form-data\">\n"; while ( list($key,$val) = each($this->hidden) ) { $output .= "\n"; } $output .= "
\n"; while ( list($key,$val) = each($this->input) ) { switch ($val['type']) { case 'text': $output .= "
\n"; $output .= " " . $val['label'] . ":\n"; $output .= " \n"; $output .= "
\n"; break; case 'password': $output .= "
\n"; $output .= " " . $val['label'] . ":\n"; $output .= " \n"; $output .= "
\n"; break; case 'file': $output .= "
\n"; $output .= " " . $val['label'] . ":\n"; $output .= " \n"; $output .= "
\n"; break; case 'textarea': $output .= "
\n"; $output .= " " . $val['label'] . ":\n"; $output .= " \n"; $output .= "
\n"; break; case 'select': $output .= "
\n"; $output .= " " . $val['label'] . ":\n"; $output .= " \n"; $output .= "
\n"; break; case 'captcha': $output .= "
\n"; $output .= " Enter numbers:\n"; $output .= " \n"; $output .= "
\n"; break; default: break; } } $output .= "
\n"; $output .= "  \n"; $output .= " "; while ( list($key,$val) = each($this->submit) ) { $output .= ""; } if ( $this->reset ) { $output .= "reset . "\">"; } $output .= "\n"; $output .= "
\n"; $output .= "
\n"; $output .= "
\n"; return $output; } } ?>