Jump to content

drupal form


phprookie72

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/227300-drupal-form/
Share on other sites

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;
}

Link to comment
https://forums.phpfreaks.com/topic/227300-drupal-form/#findComment-1173666
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.