dongyong5255 2012-02-01 22:45
浏览 13

检索webform中选择选项的值

I would like to validate the company name chosen of the submitted from a select option - "Company"

When I try $form_values['submitted_tree']['company_1']; it shoes me the key instead of the string value. Eg.$form_values['submitted_tree']['company_1']; shows '1', which is the key of the selected option.

I tried this, but it still prints the key '1' instead of its value.

<?php
$_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) && ($value1 == $value2))
{
    drupal_set_message(print_r($form['submitted_tree']['company_2']['#options'][$key2]));
}
?>

The code which I use to populate the select option is

$array = array();
if ($_SESSION['major'] == 0) {
$sql = db_query("Select data from webform_submitted_data where nid = 2133 and cid = 20 and sid in (SELECT sid FROM webform_submitted_data WHERE nid = 2133 and cid =30 and no = 0) and data not in (SELECT data FROM webform_submitted_data where nid = 2134 and cid=15 group by data having COUNT(*) > 6) order by data ASC");
while($row = db_fetch_object($sql)) {
    $array[] = $row->data; 
}
}
return $array;

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.

  • 写回答

1条回答 默认 最新

  • dongwenhui8900 2012-02-02 02:16
    关注

    Even I had this problem some time ago. You could always run the query that you used to populate the select options again in your validation function. SInce you know the key you can find the value of the selected element as well. Hope this helps!

    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮