SHARE
TWEET

Untitled

a guest Jul 19th, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. function search_main_form($form, &$form_state) {
  4.   $location_li2 = array(array(""), array("Albania"), array("Austria"), array("Belarus"), array("Belgium"), array("Bhutan"), array("Bulgaria"), array("Cambodia"), array("Canada", array("Alberta", "Atlantic", "British Columbia|BC", "Manitoba|MB", "Ontario|ON", "Quebec|QC|PQ", "Saskatchewan|SK")), array("Chile", array("Maipo")), array("China", array("Anhui", "Beijing", "Boxing", "Chongqing", "Dezhou", "Foshan", "Fujian", "Guangdong|GuangDong", "Guangxi", "Guizhou", "Guodian", "Hainan", "Hebei|Heibei", "Heilongjiang", "Henan|Henau|Hennan|Hnan", "HuangHe", "Hunan|HuNan", "Jiangsu", "Jiangxi", "Jilin", "Jinan", "Liaocheng", "Nanjing", "Nantong", "Shaanxi", "Shandong|Shangdong|SD", "Shanghai", "Shanxi", "Shenxian", "Sichuan", "Siyang", "Tianjin", "Wenzu", "Wuzhou", "Xinjiang", "Yunnan|Yun Nan", "Zhangqiu")), array("Colombia", array("Antioquia", "Atlantico", "Caldas", "Cundinamarca", "Quindio")), array("Croatia"), array("Czech Republic"), array("Denmark"), array("France"), array("Germany"), array("Hong Kong"), array("Hungary"), array("India", array("Mizoram")), array("Italy"), array("Japan", array("Aichi", "Aomori", "Chiba", "Ehime", "Fukushima", "Gunma", "Hokkaido", "Ibaraki", "Ishikawa", "Iwate", "Kagoshima", "Kyoto", "Nagasaki", "Niigata", "Osaka", "Saga", "Saitama", "Shiga", "Shizuoka", "Tochigi", "Yamagata", "Yamaguchi", "Yamanashi")), array("Laos"), array("Latvia"), array("Lithuania"), array("Malaysia", array("Sarawak", "Selangor")), array("Mexico", array("Morelos")), array("Myanmar"), array("Netherlands"), array("Philippines"), array("Poland"), array("Portugal"), array("Romania"), array("Russia"), array("Serbia"), array("Singapore"), array("Slovakia"), array("Slovenia"), array("South Korea"), array("Spain", array("Madrid")), array("Switzerland"), array("Taiwan"), array("Thailand"), array("Turkey"), array("USA", array("Alabama|AL", "Arizona|AZ", "Arkansas|AR", "California|CA", "Colorado|CO", "Georgia|GA", "Hawaii|HI", "Illinois|IL", "Indiana|IN", "Iowa|IA", "Kansas|KS", "Kentucky|KY", "Michigan|MI", "Minnesota|MN", "Mississippi|MS", "Missouri|MO", "Nebraska|NE", "Nevada|NV", "North Carolina|NC", "North Dakota|ND", "Ohio|OH", "Oklahoma|OK", "Pennsylvania|PA", "South Carolina|SC", "South Dakota|SD", "Tennessee|TN", "Texas|TX", "Utah|UT", "Virginia|VA", "Wisconsin|WI", "Wyoming|WY")), array("Ukraine"), array("United Kingdom"), array("Uruguay"), array("Viet Nam", array("An Giang", "Bac Lieu", "Bac Ninh", "Binh Duong", "Can Tho", "Dien Bien", "Dong Nai|DongNai", "Dong Thap", "Hai Duong", "Hai Phong", "Hanoi", "Hau Giang", "Ho Chi Minh", "Hung Yen", "Lao Cai", "Long An", "Nam Dinh", "Nghe An", "Quang Ninh", "Son La", "Tay Ninh", "Thai Binh", "Tien Giang", "Yen Bai")));
  5.  
  6.  
  7.   $form['form_wrapper'] = array(
  8.     '#prefix' => '<div id="form_wrapper">',
  9.     '#suffix' => '</div>',
  10.   );
  11.  
  12.   $form['form_wrapper']['properties'] = array(
  13.     '#prefix' => '<h2>Filter by sequence properties</h2>
  14.                   <div><table width="50%">',
  15.     '#suffix' =>  '</table></div>', //<br>',
  16.   );
  17.  
  18.  
  19. //Sample Collection Location
  20.   //drupal_set_message(print_r($location_li2), true); //$location_li2 is not being read correctly
  21.   $country_li = array();
  22.   $state_li = array("" => "");
  23.   foreach($location_li2 as $location_li) {
  24.     $country_li[$location_li[0]] = $location_li[0];
  25.     if (isset($_POST['ddl1b']) && in_array($location_li[0], $_POST['ddl1b']) && sizeof($location_li) > 1) {
  26.       foreach($location_li[1] as $state) {
  27.         $state_li[$location_li[0].':'.$state] = explode('|', $state)[0]; //include country in state value
  28.       }
  29.     }
  30.   }
  31.   $form['#state_li'] = $state_li;
  32.   $form['form_wrapper']['properties']['collection_location']['title_wrapper'] = array(
  33.     '#prefix' => '<tr><td class="search_input_td" width="50%"><b>Sample Collection Location</b></td><td class="search_input_td">',
  34.     '#suffix' => '</td></tr>',
  35.   );
  36.   $form['form_wrapper']['properties']['collection_location']['title_wrapper']['ddl1b'] = array(
  37.     '#prefix' => '<div style="display:inline-block; width:50%">', //width:49%">',
  38.     '#suffix' => '</div>',
  39.     '#type' => 'select',
  40.     '#multiple' => TRUE,
  41.     '#options' => $country_li,
  42.     '#id' => 'ddl1b',
  43.     '#attributes' => array(
  44.       'autocomplete' => 'off',
  45.       //'onchange' => '',
  46.     ),
  47.     '#ajax' => array(
  48.       'callback' => 'add_state_select',
  49.       'wrapper' => 'ddl2b_wrapper',
  50.       'progress' => array('type' => 'none'),
  51.     ),
  52.   );
  53.   $form['form_wrapper']['properties']['collection_location']['title_wrapper']['ddl2b_wrapper'] = array(
  54.     '#prefix' => '<div id="ddl2b_wrapper" style="display:inline-block; width:50%">',
  55.     '#suffix' => '</div>',
  56.   );
  57.   $form['form_wrapper']['properties']['collection_location']['title_wrapper']['ddl2b_wrapper'] = add_state_select($form, $form_state);
  58.  
  59.   $form['form_wrapper']['table_button'] = array(
  60.     '#type' => 'submit',
  61.     '#value' => 'Submit',
  62.     '#submit' => array('activate_table'),
  63.     '#ajax' => array(
  64.       'callback' => 'rebuild_form',
  65.       'wrapper' => 'form_wrapper',
  66.     ),
  67.   );
  68.  
  69.   if (!empty($form_state['table'])) {
  70.     $form['form_wrapper']['raw_html'] = array(
  71.       '#type' => 'markup',
  72.       '#markup' => '<br><br>TEST!',
  73.     );
  74.   }
  75.  
  76.   return $form;
  77. }
  78.  
  79.  
  80. function rebuild_form($form, $form_state) {
  81.   return $form['form_wrapper'];
  82. }
  83.  
  84. function activate_table($form, &$form_state) {
  85.   $form_state['table'] = TRUE;
  86.   $form_state['rebuild'] = TRUE;
  87. }
  88.  
  89. function add_state_select($form, &$form_state) {
  90.   //drupal_set_message('triggered add_state_select()');
  91.   $state_li = $form['#state_li'];
  92.   $form['form_wrapper']['properties']['collection_location']['title_wrapper']['ddl2b_wrapper'] = array(
  93.     '#prefix' => '<div id="ddl2b_wrapper" style="display:inline-block; width:50%">',
  94.     '#suffix' => '</div>',
  95.   );
  96.   if (sizeof($state_li) > 1) {
  97.     //drupal_set_message('triggered build conditional');
  98.     $form['form_wrapper']['properties']['collection_location']['title_wrapper']['ddl2b_wrapper']['ddl2b'] = array(
  99.       '#type' => 'select',
  100.       '#multiple' => TRUE,
  101.       '#options' => $state_li,
  102.       '#id' => 'ddl2b',
  103.       '#attributes' => array(
  104.         'autocomplete' => 'off',
  105.         //'multiple' => 'true',
  106.       ),
  107.     );
  108.   }
  109.   return $form['form_wrapper']['properties']['collection_location']['title_wrapper']['ddl2b_wrapper'];
  110. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top