开发者

Capture value of Select list when form is submitted - Drupal

I need to use the selected value of a select list when the form is submitted (in submit handler). I am familiar with using the Form API, but can't find the solution on drupal.org.

For example, I am loading a select list with 3 options. When the user selec开发者_StackOverflow中文版ts a value and submits. I want to grab that value and use it in an SQL query that I have located in my submit handler.

$form['my_select'] = array('#type = 'select',
                           '#title' = 'Pick a value',
                           '#options' = array('dog' => 'Choice One', 
                                              'cat' => 'Choice two',
                                              'bird'=> 'Choice three'),
                          );

Then I want to use the value the user selected in a custom submit handler.


Finally got this to work:

$form_state['values']['my_select'] = array('0' => array('value' => $form['my_select']['#value'])


$form['category'] = array(
'#type'=>'select',
'#title' => 'category',
'#required' => TRUE, 
'#options' => array('pdf'=>'pdf','jpg'=>'jpg','png'=>'png'),
'#multiple' => false,

);

  function myform_simpleform_submit($form, &$form_state)
  {
    $category=$form['category']['#value'];
    db_query("INSERT INTO {contact} (name,category) VALUES ('$name','$category')");
   }

check it will work 200%

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜