Drupal 7 set default value from database in hook_form I have implemented a hook menu:

$menu['question-view'] = array(
  'title' =&gt; 'Question View',
  'page callback' =&gt; 'item_view',
  'access arguments' =&gt; array('access question view'),
);


item_view callback is generated using table theme:

$output = theme('table', array(
  'header' =&gt; $header,
  'rows' =&gt; $rows,
));

$output .= theme('pager');
return $output;


which displays a table like this:

Question            Edit
Question1     Click here to edit
Question2     Click here to edit
Question3     Click here to edit


where "Question1", "Question2", and "Question3" are just questions like "What is your name?", which were all obtained from questions table in database.

When I click "Click here to edit", it should go to a form containing that question. For example, when I click edit beside Question2, the form should display Question2 as default value in the $form['question'] field.

I want to do something like:

$form['question'] = array(
  '#title' =&gt; t('Question'),
  '#type' =&gt; 'textfield',
  '#default_value' =&gt; ... // This should come from the question where I clicked.
);


Question:
How should I set the default value of $form['question']?
Basically, you have to add an indicator with edit question link i.e query string to load the selected question from database and pass the default value to the form.


  A query string is the part of a uniform resource locator (URL) that contains data to be passed to web applications.


"Click here to edit" link may look like (clean URL enabled): 

http://www.your-domain.com/item_view/question/44 

or

http://www.your-domain.com/question/44/edit

44 in both cases represent question id.

Then, take question id from the url and pass it to a mysql query to retrieve question title and assign it to #default_value  

Example as follow:

function question_form() {

  $question_id = 0;

  // assuming url: www.your-domain.com/item_view/question/44
  if (arg(1) == 'question') {
    $question_id = arg(2);
  }

  // retrieve question title by question id
  $query = db_select('questions', 'q')
    -&gt;fields('q', array('question_title'))
    -&gt;condition('q.question_id', $question_id);
  $result = $query-&gt;execute()-&gt;fetchAssoc();


  $form['question'] = array(
    '#title' =&gt; t('Question'),
    '#type' =&gt; 'textfield',
    '#default_value' =&gt; ($result &amp;&amp; isset($result['question_title']))? $result['question_title'] : '';
  );
}