0

カスタム関数からラジオ ボタンを生成する Drupal 7 のフォームがあります。送信時に、選択したボタンのインデックス値を取得し、別のカスタム関数で処理します。私の問題は、最初のラジオ ボタンが選択されている場合、インデックス ($form_state['values']['stores']) が生成されないことです。最初のボタンを対応する配列の最初の結果にハードコードすることができると思いますが、なぜこれが起こっているのかを知りたいです。

これが私のコードです:

形:

hook_form {
   global $user;
   $user_fields = user_load($user->uid);
    $zipcode = $user_fields->zip_code['und']['0']['value'];
    $defaults = !empty($form_state['values']['zip_code']) ? $form_state['values']['zip_code'] : $zipcode;
    $storename = getmystorename($defaults);
    $form['zip_code'] = array(
      '#title' => t('Zip Code'),
      '#type' => 'textfield',
      '#required' => TRUE,
      '#default_value' => $defaults,
      '#ajax' => array(
    // #ajax has two required keys: callback and wrapper.
    // 'callback' is a function that will be called when this element changes.
    'callback' => 'settings_form_callback',
    'wrapper' => 'textfields',
      ),
      );
    if(count($storename) > 0) {
    $form['textfields'] = array( 
    '#prefix' => '<div id="textfields">',
    '#suffix' => '</div>',
    '#type' => 'fieldset' );
    $form['textfields']['stores'] = array(
    '#type' => 'radios',
    '#title' => t('Choose your store:'),
    '#options' => $storename,
    '#default_value' => $storename[0], );
    } else {
      $form['textfields']['incorrect'] = array(
    '#title' => t('Sorry, there are no stores available near you.'),
    '#type' => 'fieldset', );
    }
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => 'Submit',
      );
}

送信:

hook_form_submit {
  $zipcode = $form_state['values']['zip_code'];
  //Check that results were given for the zip code
  if(!empty($form_state['values']['stores'])) {
     $linkposition = $form_state['values']['stores']; }
  //If results were given grab the store link
  //if(isset($linkposition)) {
  //querypath the array of the store name to grab link
  $mystorelinks = getmystorelink($zipcode);
  $storelink = $mystorelinks[$linkposition];
}

生成された配列:

Array ( [0] => Store1 [1] => Store2 [2] => Store3 [3] => Store4 [4] => Store5 [5] => Store6 [6] => Store7 [7] => Store8 [8] => Store9 [9] => Store10 ) 

Array ( [0] => http://www.example.com/stores/store1.html [1] => http://www.example.com/stores/store2.html [2] => http://www.example.com/stores/store3.html [3] => http://www.example.com/stores/store4.html [4] => http://www.example.com/stores/store5.html [5] => http://www.example.com/stores/store6.html [6] => http://www.example.com/stores/store7.html [7] => http://www.example.com/stores/store8.html [8] => http://www.example.com/stores/store9.html [9] => http://www.example.com/stores/store10.html ) 
4

0 に答える 0