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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.