开发者

Multistep drupal form with tables

开发者 https://www.devze.com 2023-03-24 19:30 出处:网络
Can anyone tell me how to make a multi-step drupal form which prints a table in one of the steps?- This is the code I already have, it corresponds to the second step of the form. It throws me this er

Can anyone tell me how to make a multi-step drupal form which prints a table in one of the steps?-

This is the code I already have, it corresponds to the second step of the form. It throws me this error:

Fatal error: Cannot unset string offsets in C:\wamp\www\academicus\includes\form.inc on line 497

function listarAlumnos($nombre, $apellido) {
    if($nombre=='') {
       $consulta="SELECT * FROM Pinteres WHERE PinApe1='".$apellido."' or PinApe2='".$apellido;
    } else if ($apellido=='') {     
       $consulta="SELECT * FROM Pinteres WHERE PinNom1='".$nombre."' or PinNom2='".$nombre."'";
    } else {
       $consulta="SELECT * FROM Pinteres WHERE (PinNom1='".$nombre."' or PinNom2='".$nombre."') AND (PinApe1='".$apellido."' or PinApe2='".$apellido."')";
    }   
    $resultado=consultarContacta($consulta);    
    $form=array();
    $header = array(t('Id'), t('Primer nombre'), t('Segundo nombre'), t('Primer apellido'), t('Segundo apellido'), t('Direccion'), t('Telefono'), t('Celular'), t('Email'));
    $rows = array();
    while ($rs=odbc_fetch_array($resultado)) {
        $row=array();
        $id=$rs['PinId'];       
        $primerNombre=$rs['PinNom1'];
        $segundoNombre=$rs['PinNom2'];
        $primerApellido=$rs['PinApe1'];
        $segundoApellido=$rs['PinApe2'];
        $direccion=$rs['PinDir'];
        $telefono=$rs['PinTelPri'];
        $celular=$rs['PinTelCel'];
        $email=$rs['PinEMail'];     
        $row[] = $id;
        $row[] = $primerNombre;
        $row[] = $segundoNombre;
        $row[] = $primerApellido;
        $row[] = $segundoApellido;
        $row[] = $direccion; 
        $row[] = $telefono;
        $row[] = $celular;
        $row[] = $email; 
        $rows[] = $row;
    };
    $form['IdIngresado'] = array (
        '#title' => t('Id interesado a importar'),
        '#type' => 'textfield',
        '#开发者_开发知识库required' => TRUE,    
        '#description' => t('Ingrese el id del interesado a importar de los listados arriba.')
    );
    $form['CedulaIngresada'] = array (
        '#title' => t('Cedula interesado a importar'),
        '#type' => 'textfield',
        '#required' => TRUE,    
        '#description' => t('Ingrese la cedula del interesado a importar.')
    );  
    $form['finalizar'] = array (
        '#type' => 'submit',
        '#value' => t('Finalizar')
    );
    $output .= theme('table', $header, $rows);
    $output .= drupal_render($form);
    return $output;
}

I could make it work using some code like this:

$form['serial'] = array(
    '#type' => 'textfield',
    '#title' => t('serial number'),
    '#prefix' => '<table><tr><td>',
    '#suffix' => '</td>',
);

but I know it's not the proper way of doing it.


I assume you know how to do the multi-step form. For the table, you can use Drupal's table theme function. If the table contains only markup, you can do something like this:

$form['table'] = array ('#value' => theme('table', $headers, $rows));

$headers are the table headers and $rows are your data.

If the table contains actual form elements (such as selects, textfields, etc.), you can wrap them in a form element that calls a theme function, like so:

$form['table'] = array ('#theme' => 'output_table');

$form['table']['element_1'] = array (...);
$form['table']['element_2'] = array (...);

Within 'theme_output_table', generate your $headers and $rows to feed to 'theme_table' by calling 'drupal_render' on the relevant form elements that are children of $form['table'].

0

精彩评论

暂无评论...
验证码 换一张
取 消