I have a form, and I want to get the selected value of $form['dropdown_third'] and then use the value to create my table.

What should I write in Submit function?

function find_tryk_filter_test_page($form, &$form_state) {

$options_first = find_tryk_filter_test_first_dropdown_options();
$value_dropdown_first = isset($form_state['values']['dropdown_first']) ? $form_state['values']['dropdown_first'] : key($options_first);

$form['dropdown_first'] = array(
    '#type' => 'select',
    '#title' => 'Type',
    '#options' => $options_first,
    '#default_value' => $value_dropdown_first,
    '#ajax' => array(
        'event' => 'change',
        'callback' => 'find_tryk_filter_test_ajax_callback',
        'wrapper' => 'dropdown_second_replace',

$form['dropdown_second'] = array(
    '#type' => 'select',
    '#title' => 'Producent',        
    '#prefix' => '<div id="dropdown_second_replace">',
    '#suffix' => '</div>',
    '#options' => find_tryk_filter_test_second_dropdown_options($value_dropdown_first),
    '#default_value' => isset($form_state['values']['dropdown_second']) ? $form_state['values']['dropdown_second'] : '',
    '#ajax' => array(
        'event' => 'change',
        'callback' => 'find_tryk_filter_test_2_ajax_callback',
        'wrapper' => 'dropdown_third_replace',

if (!empty($value_dropdown_second)){
    $options_second = find_tryk_filter_test_second_dropdown_options($value_dropdown_second);    
    $value_dropdown_second = isset($form_state['values']['dropdown_second']) ? $form_state['values']['dropdown_second'] : key($options_second);
    $options_second = array();  
    $value_dropdown_second = isset($form_state['values']['dropdown_second']) ? $form_state['values']['dropdown_second'] : key($options_second);

//echo $options_second;
$form['dropdown_third'] = array(
    '#type' => 'select',
    '#title' => 'Model',       
    '#prefix' => '<div id="dropdown_third_replace">',
    '#suffix' => '</div>',        
    '#options' => find_tryk_filter_test_third_dropdown_options($value_dropdown_second),
    '#default_value' => isset($form_state['values']['dropdown_third']) ? $form_state['values']['dropdown_third'] : '',

$form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Find trykluft element'),  
    '#ajax' => array(
        'callback' => 'find_tryk_filter_test_ajax_result_callback',
        'wrapper' => 'result-wrapper',
        'method' => 'replace',
        'effect' => 'fade',
        '#prefix' => '<div id="replace_hotelbook_div">',
        '#suffix' => '</div>'

$header = array('Navn', 'Shoplink', 'Brochure');

$options_third = find_tryk_filter_test_third_dropdown_options($value_dropdown_second);  
$value_dropdown_third = isset($form_state['values']['dropdown_third']) ? $form_state['values']['dropdown_third'] : key(0);
$query = db_query("SELECT node.title, fdfs.field_shoplink_value, fm.uri
    FROM node 
    JOIN field_data_field_model AS fdfm ON
    fdfm.entity_id = node.nid
    JOIN field_data_field_producent AS fdfp ON
    fdfm.entity_id = fdfp.entity_id
    JOIN field_data_field_shoplink AS fdfs
    ON fdfs.entity_id = fdfm.entity_id
    JOIN field_data_field_brochure AS fdfb
    ON fdfb.entity_id = fdfm.entity_id
    JOIN file_managed AS fm ON
    fm.fid = fdfb.field_brochure_fid
    JOIN taxonomy_term_data AS ttd
    ON fdfp.field_producent_tid = ttd.tid
    WHERE fdfm.field_model_value = '".$value_dropdown_third."'");                   

$rows = array();

foreach ($query as $row) {
    $rows[] = array($row->title, $row->field_shoplink_value, $row->uri);                        

$form['webform_results'] = array(
  '#theme' => 'table',
  '#rows' => $rows,
  '#header' => $header

return $form;

  • 1
    Sorry about the bad layout and the long code. Aug 12, 2014 at 10:26
  • No problem. I fixed it for you. Next time take a few minutes and play with the buttons on top of the edit window, you can format code as code block with one click :)
    – Mołot
    Aug 12, 2014 at 10:29
  • @MahyarFarshi Just a note, but that db_query is not ideal. You should consider using EntityFieldQuery instead. Also, currently there's a potential SQL injection vulnerability in that SQL, because you're not using db query placeholders at all. Aug 12, 2014 at 11:20
  • you have some good points about sql injection. I didnt think about it. Aug 13, 2014 at 7:58

1 Answer 1


What should I write in Submit function?

That's up to you, depends what you want to do. It sounds like you're just unsure how to get access to the submitted values. Those reside in $form_state['values'], so:

$value = $form_state['values']['dropdown_third'];
  • I tried this one but I got an fatal error :( Aug 12, 2014 at 11:52
  • Where have you got the idea that adding that line of code in the submit function is what you're supposed to do? Or are you just adding random bits of code to see what happens?
    – Clive
    Aug 12, 2014 at 11:54
  • I try some random code to see what happens. I really dont know what to write in Submit function :( Aug 12, 2014 at 11:57
  • You'll need to get yourself more familiar with the Drupal API first then. We don't have a code writing service here, and teaching you everything you'll need to know to perform an as yet unspecified task is not something we can help you with here. As a hint, I would try breaking your questions down into their smallest possible parts, and then researching how to solve each individual problem separately. You'll find it much easier that way
    – Clive
    Aug 12, 2014 at 12:02
  • You are right, I wil try to break my question in smaller parts. Is it better to do it in here or should I create a question for each of them? Aug 12, 2014 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.