通过数据库自动化处理生成表单

dbc->query($form_query);
        $output = NULL;
        $output .= '
'; //generate form items based on fields while ($field = $row->fetch_field()) { //print show_array($field); //form field error class isset($_SESSION[str_replace(' ', '_', $field->name)]) ? $input_class = $_SESSION[str_replace(' ', '_', $field->name)]: $input_class = ''; //form field default value isset($_POST[str_replace(' ', '_', $field->name)]) ? $field_value = $_POST[str_replace(' ', '_', $field->name)]: $field_value = ''; //form field password type (preg_match('/\s*password\s*/', $field->name)) ? $field_type = 'password': $field_type = 'text'; //form input/textarea type ($field->length > 100) ? $input_type = '' . $field_value . '': $input_type = ''; $output .= $input_type; //reset empty error class $_SESSION[str_replace(' ', '_', $field->name)] = ''; } //cancel submit button switch ($form_cancel) ? $cancel = '': $cancel = ''; //form sumit button $output .= ' ' . $cancel; $output .= '
'; return $output; } //with a few lines of codes you can automatically generate the registration form, of course you need to setup a database for this to work function user_register() { //form get function input $form_query = 'SELECT name as user, password, password as "retype password", email FROM user LIMIT 1'; $form_name = 'register'; $form_action = ''; $form_method = 'post'; $form_cancel = 1; $output = NULL; if(isset($_GET['q']) && $_GET['q'] == 'register') { $output .= $this->form_get($form_query, $form_name, $form_action, $form_method, $form_cancel); } else { $output .= 'Not a member yet? ' . ucwords($form_name) . ''; } return $output; } ?>

 

你可能感兴趣的:(通过数据库自动化处理生成表单)