I would like to validate the company name chosen in a form in a "select" form field.

When I try $form_values['submitted_tree']['company_1']; it shows me the key instead of the string value.

I tried the following code, but it still prints '1' (the key) instead of the value associated with the key.

    $_page_num = $form_state['values']['details']['page_num'];
    $key1 = $form_state['values']['submitted_tree']['company_1'];
    $value1 = $form['submitted_tree']['company_1']['#options'][$key1];
    $key2 = $form_state['values']['submitted_tree']['company_2'];
    $value2 = $form['submitted_tree']['company_2']['#options'][$key2];

    if (($_page_num == 2) &amp;&amp; ($value1 == $value2)) {
      drupal_set_message(print_r($form['submitted_tree']['company_2']['#options'][$key2]));
    }


Could anyone help me to retrieve the actual text value displayed in select option chosen? I have tried $form_state as well, but it returns the same result.


Question: c++ getline and stringstream
Answer: If &gt;&gt; sees that there is nothing left in the stringstream, it will leave the variable untouched - so dx.out keeps its value from the last line. However, you can do

ss &gt;&gt; dx.in &gt;&gt; dx.name &gt;&gt; dx.id;
if (!(ss &gt;&gt; dx.out))
    dx.out = "";


because ss &gt;&gt; dx.out returns ss, and when a stream is converted to a bool (such as when it is used in an if condition), it returns false if the last read attempt failed.