Location: PHPKode > scripts > jForm > jform/jForm.php
<?php
/*
*
* jForm version 1.0
* by Johan De Klerk (hide@address.com)
* Freely Distributable
*
*/

class jForm {

    function jBeginForm($assoc) {
        $form_string = '<form ';

        if (!empty($assoc)) {

            foreach($assoc as $key => $val) {
                $form_string .= $key.'="'.$val.'" ';
            }
        }

        return $form_string .= '>'."\n";
    }
    
    function jInput($assoc) {
        $form_string = '<input type="text" ';

        if (!empty($assoc)) {

            foreach($assoc as $key => $val) {
                $form_string .= $key.'="'.$val.'" ';
            }
        }

        return $form_string .= '></input>'."\n";
    }
    
    function jHidden($assoc) {
        $form_string = '<input type="hidden" ';

        if (!empty($assoc)) {

            foreach($assoc as $key => $val) {
                $form_string .= $key.'="'.$val.'" ';
            }
        }

        return $form_string .= '></input>'."\n";
    }
    
    function jSelect($assoc,$values,$selected=0) {
        $form_string = '<select ';

        if (!empty($assoc)) {

            foreach($assoc as $key => $val) {
                $form_string .= $key.'="'.$val.'" ';
            }
        }

        $form_string .= '>'."\n";
        
        if (!empty($values)) {

            for ($i = 0; $i < count($values); $i++) {
                if ($i == $selected) {
                    $form_string .= '<option value="'.$i.'" selected>'.$values[$i].'</option>'."\n";
                }
                else {
                    $form_string .= '<option value="'.$i.'">'.$values[$i].'</option>'."\n";
                }
            }
        }
        
        return $form_string .= '</select>'."\n";
    }
    
    function jTextArea($assoc,$value='') {
        $form_string .= '<textarea ';
        
        foreach($assoc as $key => $val) {
            $form_string .= $key.'="'.$val.'" ';
        }
        
        $form_string .= '>';
        
        if (!empty($value)) {
            $form_string .= $value;
        }
        
        return $form_string .= '</textarea>'."\n";
    }
    
    function jRadioButton($assoc,$values) {
        $form_string='';

        if (!empty($values)) {
            for ($i = 0; $i < count($values); $i++) {

                $form_string .= '<input type="radio" ';
                
                if (!empty($assoc)) {
                    foreach($assoc as $key => $val) {
                        $form_string .= $key.'="'.$val.'" ';
                    }
                }

                $form_string .= '>';
                $form_string .= $values[$i] . '</input><br>'."\n";
            }
        }

        return $form_string .= '</input>'."\n";
    }
    
    function jCheckBox($assoc,$value,$checked='no') {
        $form_string = '<input type="checkbox" ';

        if (!empty($assoc)) {

            foreach($assoc as $key => $val) {
                $form_string .= $key.'="'.$val.'" ';
            }
        }
        
        if (!strcmp($checked,'yes')) {
            $form_string .= 'checked';
        }

        return $form_string .= '>'.$value.'</input>'."\n";
    }
    
    function jReset() {
        $form_string = '<input type="reset">';
        return $form_string .= '</input>'."\n";
    }
    
    function jSubmit($value='',$imagesrc='') {
        $form_string = '<input type="submit" ';
        
        if (strcmp($value,'')) {
            $form_string .= 'value="'.$value.'" ';
        }
        
        if (strcmp($imagesrc,'')) {
            $form_string = '<input type="image" ';
            $form_string = 'src="'.$imagesrc.'" ';
        }
        
        return $form_string .= '></input>';
    }

    function jEndForm() {
        return '</form>';
    }
}
?>
Return current item: jForm