views:

23

answers:

1

I have a tableselect form that lists several items. When a user selects one or more items, and clicks the edit button, I want a new form to show up that lets them edit the items.

I have the new form structure being generated, but I can't get it to show up after the edit button is clicked.

Currently, nothing seems to happen. I know that the tableselect form is being submitted correctly, and the function to create the edit term form is working correctly. I tested it with drupal_set_message and var export.

So, how do I get the new form to show?

Here is my relevant code:

/**
 * Generate form for listing terms
 */
function markit_form_terms_list()
{

    $form = array();
    $form['terms'] = array(
        '#type' => 'fieldset',
        '#title' => t('List of Terms'),
        );
    $header = array(t('Name'), t('ID'), t('SetID'));
    $form['terms']['items'] = array(
          '#type' => 'tableselect',
          '#header' => $header,
          '#title' => t('Terms'),
          '#options' => markit_get_array_terms(),//drupal_map_assoc($header, 'markit_get_array_terms'),
          '#tree' => TRUE,

    );
    $form['terms']['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Edit Term'),
        '#submit' => array('markit_form_terms_list_submit'),
        );
    /*$form['terms']['delete'] = array(
        '#type' => 'submit',
        '#value' => t('Delete Term'),
        '#submit' => 'markit_form_terms_delete'
        );*/
    return $form;
}

/**
 * Generate form to edit the terms.
 * @param <type> $form
 * @param <type> $form_state
 * @return string
 */
function markit_form_term_edit($form, $form_state)
{
    $newform = array();
    $newform['termstoedit'] = array(
        '#type' => 'fieldset',
        '#title' => t('Edit Term/s'),
        );
    foreach($form_state['values']['items'] as $row)
    {
        if($row!=0)//if a row is not selected, it will be 0. So don't select rows equal to 0.
        {
            $terminfo = markit_get_markterms($row);
            drupal_set_message(var_export($terminfo,true));//['term_name']);
            drupal_set_message($terminfo[0]['term_name']);
            $newform['termstoedit'][$terminfo[0]['term_id']] = array(
              '#type' => 'textfield',
              '#title' => t('Term:'),
              '#default_value' => $terminfo[0]['term_name'],
              '#size' => 60,
              '#maxlength' => 128,
              '#required' => TRUE,
            );
        }
    }    
    $newform['termstoedit']['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Edit Term'),
        '#submit' => array('markit_form_term_edit_submit'),
        );
    drupal_set_message(var_export($newform,true));
    return $newform;
}

function markit_form_terms_list_submit($form,$form_state)
{
    drupal_set_page_content(drupal_build_form('markit_form_term_edit', $form_state));
}

I believe I am not using the correct code in the markit_form_terms_list_submit function. I've tried several different things, but it hasn't worked yet. And the Google searches I've done haven't helped either. I also have searched the Drupal API and Drupal Form API sites extensively.

Anyway, I think that's all the info you might need in order to help me. Thanks in advance!

A: 

I believe you may have better luck if you have one form function with differing fields being shown depending on the output.

If you do this you will even be able to use the form ajax methods to auto update your form.

Have a look at this howto to see if you think the approach will work for you.

Jeremy French
Good tip, and I'll look into it. But I still want to know how to do it without ajax.
David R.
Right, trying it. Still won't work do everything correctly. For the tales of my trials: http://drupal.org/node/872088
David R.