phprookie72 Posted February 10, 2011 Share Posted February 10, 2011 i am trying to write a form in drupal, here is my plan. I have a database of players name and number, I would like to write a form that allows user to change players number, my question is how would i create a form that display values from the database? The initial form would be players name (title) on left side (name are taken from database) and players number (textfield) on right side with default value from database. I guess my question is how do you display dynamic values in drupal form, instead of hard codeing? Quote Link to comment https://forums.phpfreaks.com/topic/227300-drupal-form/ Share on other sites More sharing options...
haku Posted February 13, 2011 Share Posted February 13, 2011 Something like this (D6): function my_form($form_state, $uid) { $data = db_fetch_array(db_query('SELECT name, age, weight FROM {user_data} WHERE uid = %d', $uid)); $form['name'] = array ( '#type' => 'textfield', '#title' => t('Name'), '#default_value' => $data['name'], // This is where you enter the default dynamic data ); $form['age'] = array ( '#type' => 'textfield', '#title' => t('Age'), '#default_value' => $data['age'], // This is where you enter the default dynamic data ); $form['weight'] = array ( '#type' => 'textfield', '#title' => t('Weight'), '#default_value' => $data['weight'], // This is where you enter the default dynamic data ); return $form; } Quote Link to comment https://forums.phpfreaks.com/topic/227300-drupal-form/#findComment-1173666 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.