type = $type; if ( ($type == 'text') OR ($type == 'password') ) { $this->size = 20; $this->maxlength = 20; } if ( ($type == 'textarea') ) { $this->cols = 40; $this->rows = 4; } if ( ($type == 'submit') ) { $this->value = $name; } } else { die("Error: incorrect field type when creating class instance
\n"); } } else { die("Error: field type must be specified when creating class instance
\n"); } if ( strlen($name) ) { $this->name = $name; } else { die("Error: field name must be specified when creating class instance
\n"); } } function create() { if ( ($this->type == 'text') ) { $html = $this->createTextField(); } if ( ($this->type == 'password') ) { $html = $this->createPasswordField(); } if ( ($this->type == 'hidden') ) { $html = $this->createHiddenField(); } if ( ($this->type == 'textarea') ) { $html = $this->createTextArea(); } if ( ($this->type == 'select') ) { $html = $this->createSelectMenu(); } if ( ($this->type == 'radiobuttons') ) { $html = $this->createRadioButtons(); } if ( ($this->type == 'radiobutton') ) { $html = $this->createRadioButton(); } if ( ($this->type == 'checkbox') ) { $html = $this->createCheckBox(); } if ( ($this->type == 'checkboxes') ) { $html = $this->createCheckBoxes(); } if ( ($this->type == 'submit') ) { $html = $this->createSubmitButton(); } return($html); } function display() { echo $this->create(); } function css_class_parameter($css_class) { if ( strlen($css_class) ) { $html = " class=\"" . $css_class . "\""; } else { $html = ""; } return($html); } function createTextField() { if ( !strlen($this->name) ) { return("Error: unable to create text field, name of field not specified.
\n"); } if ( $this->size && is_numeric($this->size) ) { $size = $this->size; } else { $size = 20; } if ( $this->maxlength && is_numeric($this->maxlength) ) { $maxlength = $this->maxlength; } else { $maxlength = 20; } if ( $maxlength < $size ) { $maxlength = $size; } $css_class_html = $this->css_class_parameter($this->css_class); $html = "name . "\" id=\"" . $this->name . "\" value=\"" . htmlspecialchars(stripslashes($this->value)) . "\" size=\"" . $size . "\" maxlength=\"" . $maxlength . "\"" . $css_class_html . " />\n"; return($html); } function createPasswordField() { if ( !strlen($this->name) ) { return("Error: unable to create password field, name of field not specified.
\n"); } if ( $this->size && is_numeric($this->size) ) { $size = $this->size; } else { $size = 20; } if ( $this->maxlength && is_numeric($this->maxlength) ) { $maxlength = $this->maxlength; } else { $maxlength = 20; } if ( $maxlength < $size ) { $maxlength = $size; } $css_class_html = $this->css_class_parameter($this->css_class); $html = "name . "\" id=\"" . $this->name . "\" value=\"" . htmlspecialchars(stripslashes($this->value)) . "\" size=\"" . $this->size . "\" maxlength=\"" . $this->maxlength . "\"" . $css_class_html . " />\n"; return($html); } function createHiddenField() { if ( !strlen($this->name) ) { return("Error: unable to create hidden field, name of field not specified.
\n"); } $html = "name . "\" name=\"" . $this->name . "\" value=\"" . htmlspecialchars(stripslashes($this->value)) . "\" />\n"; return($html); } function createTextArea() { if ( !strlen($this->name) ) { return("Error: unable to create text area field, name of field not specified.
\n"); } if ( $this->cols && is_numeric($this->cols) ) { $cols = $this->cols; } else { $cols = 40; } if ( $this->rows && is_numeric($this->rows) ) { $rows = $this->rows; } else { $rows = 4; } $css_class_html = $this->css_class_parameter($this->css_class); $html = "\n"; return($html); } function createSelectMenu() { //echo ("this->name: " . $this->name . "
\n"); if ( !strlen($this->name) ) { return("Error: unable to create select menu field, name of field not specified.
\n"); } $css_class_html = $this->css_class_parameter($this->css_class); if ( $this->size > 0 ) { $size_parameter = "\" size=\"" . $this->size . "\""; if ( $this->multiple ) { $multiple_parameter = " multiple=\"multiple\""; $this->name .= '[]'; } } $html = "\n"; return($html); } function createRadioButtons() { if ( !strlen($this->name) ) { return("Error: unable to create radio button fields, name of field not specified.
\n"); } if ( is_array($this->options) ) { $css_class_html = $this->css_class_parameter($this->css_class); $html = "\n"; foreach($this->options as $option) { $html .= "\n"; if ($this->value == $option['value']) { $html .= "name . "\" value=\"" . $option['value'] . "\" checked>\n"; $html .= "" . $option['label'] . "\n"; } else { $html .= "name . "\" value=\"" . $option['value'] . "\">\n"; $html .= "" . $option['label'] . "\n"; } $html .= "\n"; } $html .= "
\n"; } return($html); } function createRadioButton() { if ( !strlen($this->name) ) { return("Error: unable to create radio button fields, name of field not specified.
\n"); } $css_class_html = $this->css_class_parameter($this->css_class); if ($this->value == $this->option['value']) { $html .= "name . "\" value=\"" . $this->option['value'] . "\" checked>\n"; } else { $html .= "name . "\" value=\"" . $this->option['value'] . "\">\n"; } return($html); } function createCheckBoxes() { //echo "this->value: " . implode ( ',', $this->value ) . "
\n"; if ( !strlen($this->name) ) { return("Error: unable to create check box fields, name of field not specified.
\n"); } if ( is_array($this->options) ) { $css_class_html = $this->css_class_parameter($this->css_class); $html = "\n"; $i = 0; foreach($this->options as $option) { $html .= "\n"; if ($this->value[$i] == $option['value']) { $html .= "name . "[" . $i . "]" . "\" value=\"" . $option['value'] . "\" checked>\n"; $html .= "" . $option['label'] . "\n"; } else { $html .= "name . "[" . $i . "]" . "\" value=\"" . $option['value'] . "\">\n"; $html .= "" . $option['label'] . "\n"; } $html .= "\n"; $i++; } $html .= "
\n"; } return($html); } function createCheckBox() { //echo "this->value: " . $this->value . "
\n"; if ( !strlen($this->name) ) { return("Error: unable to create check box field, name of field not specified.
\n"); } $css_class_html = $this->css_class_parameter($this->css_class); if ($this->value == $this->option['value']) { $html .= "name . "\" value=\"" . $this->option['value'] . "\" checked>\n"; } else { $html .= "name . "\" value=\"" . $this->option['value'] . "\">\n"; } return($html); } function createSubmitButton() { if ( !strlen($this->name) ) { return("Error: unable to create submit button, name not specified.
\n"); } $css_class_html = $this->css_class_parameter($this->css_class); $html = "name . "\" value=\"" . $this->value . "\"" . $css_class_html . ">\n"; return($html); } } ?>