2

I'm building a form that is being built by pulling information from an api and loops through it. The issue I'm having is I cant seem to pass the information to the submit page.

Here is a snippit of my code, let me know if you need more:

// Loop through resources and make fieldset for each.
for($i = 0; $i < count($resources['subscriptionResources']); $i++){  
  $resource = $resources['subscriptionResources'][$i];

...

  $form['resources'][$resource['resourceID']]['add-qty'] = array(
    '#type' => 'radio',
    '#title' => t('Upgrade'),
    '#return_value' => 1,
    '#default_value' => 0,
    '#disabled' => FALSE,
    '#prefix' => "<table class='upgrade'><tr><td>",
    '#suffix' => t("</td>"),
    '#attributes' => array(
      'name' => 'upgrade',
    ),
  );

... So the outcome is, I get three different forms each with a radio button. They are all connected due to the 'name' attribute, so only one can be selected at any given time.

But when submitting, the default_value stays 0 and return_value stays 1 for all three. I'd like some way to display the information of the 'checked' radio to the submit page. Currently I'm seeing nothing (if default_value is 0) or everything is default_value = 1.

Again, let me know if you need more information.

Thanks!

2
$resourcids = array();
 // Loop through resources and make fieldset for each.
    for($i = 0; $i < count($resources['subscriptionResources']); $i++){ 
      $resource = $resources['subscriptionResources'][$i];
      $resourcids[$resource['resourceID']]=$resource['resourceID'];
    }      

      $form['resources'] = array(
        '#type' => 'radios',
        '#title' => t('Upgrade'),
        '#options' => $resourcids,
        ),
      );

you dont need to use name attributes. drupal form api give name attributes by form name.

when you submit form you get resource id in form_state['values']['resources'] of which is selected. then you identify which radio button is selected.

and By default disabled is false. so you dont need to add disabled.

dont add t() in before t("

")

'#suffix' => t("</td>"),

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy