views:

773

answers:

1

I have a simple form:

function mymodule_test_form(&$form_state, $nid) {
  form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Click me!',
  );
  $form['mymodule_status'] = array(
    '#type' => 'select',
    '#attributes' => array('class' => 'myclass'),
    '#default_value' => variable_get('mymodule_status', 0),
    '#options' => array('one', 'two', 'three', 'four', 'five'),
  );
  return $form;
}

function mymodule_test_form_submit($form, &$form_state) {
  global $user;
  db_query("INSERT INTO {mymodule} (nid, uid, number, created) VALUES (%d, %d, %d, " . time() . ")", $nid, $user->uid, $status);
}

And in my node-contenttype.tpl.php file I print drupal_get_form('mymodule_test_form', $node->nid). BTW, is it the right way to print the drupal_get_form in the template? I tried adding the drupal_get_form to the hook_nodeapi view state, but nothing outputs, so I just ended up printing it in the template.

Another thing is the default value, I'm not sure how to use that. The variable_get always is 0. Do I need to create a custom query of my own and set that as my default value? I thought the default_value is automatically retrieved by drupal or something...

Hope I can get some help. Thanks.

Edit: Found out the node id is under: $form['#parameters'][2]

+1  A: 
emmychan
Oh okay, I understand what the variable is for now. Thanks, exactly what I wanted to know. :)
Wade