简体   繁体   English

在网络表单中检索选择选项的值

[英]Retrieving value of select option in a 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']; 当我尝试$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. 显示“ 1”,这是所选选项的键。

I tried this, but it still prints the key '1' instead of its value. 我试过了,但是它仍然打印键“ 1”而不是它的值。

<?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. 我也尝试过form_state,但是它返回相同的结果。

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! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM