Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3274022
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:59:37+00:00 2026-05-17T18:59:37+00:00

I’m trying to do it for hours now, and I just can’t do it.

  • 0

I’m trying to do it for hours now, and I just can’t do it.

What I want is:

A radio or select drop-down with varying options (from the database). This part is ok, it’s just a query and building the options.

Then there are 3 text fields, each option from the above form has data for these 3 text fields.

When the user clicks/selects one of the options, i want to autocomplete the 3 text fields from the database. It’s an edit feature, the user will select one option, and the 3 forms are completed with the current data, so the user can change them, and click submit to write the update to the database.

I’m using drupal 6 and the ahah_helper module.

I have this code, which is currently completing the textfields, but when I change the first selection, it just won’t update, not even the select value itself, it just comes back to the default, like it’s not being setted or stored into the ‘storage’ from ahah_helper. I did this based on the ahah_helper_example, it can be (and probably is) totally wrong, I just started on drupal and forms.

function filiais_editar_form($form_state) {

//
// AHAH Helper stuff
//
$form = array();
ahah_helper_register($form, $form_state);


if (!isset($form_state['storage']['editar_filial']['filial']))
    $default_value = 1;
else 
    $default_value =  $form_state['storage']['editar_filial']['filial'];


$form['editar_filial'] = array(
    '#type'   => 'fieldset',
    '#prefix' => '<div id="editar-filial-wrapper">', 
    '#suffix' => '</div>',
    '#tree'   => TRUE,
    );

$query_result = db_query("SELECT DISTINCT ON (cidade) cidade, id_filial 
                        FROM filial_pf");
$cidades = array();
while($row = db_fetch_object($query_result))
    $cidades[$row->id_filial] = $row->id_filial . ' : ' . $row->cidade;

$form['editar_filial']['filial'] = array(
    '#type'             => 'select',
    '#title'            => "Escolha a filial que deseja editar",
    '#options'          => $cidades,
    '#default_value'    => $default_value,
    '#ahah' => array(
        'event'   => 'change',
        'path'    => ahah_helper_path(array('editar_filial')),
        'wrapper' => 'editar-filial-wrapper',
    ),
);

$form['editar_filial']['update'] = array(
    '#type'  => 'submit',
    '#value' => "Atualizar Dados",
    '#submit' => array('ahah_helper_generic_submit'),
    '#attributes' => array('class' => 'no-js'),
  );

    //$fid = $form_state['storage']['editar_filial']['filial'];
    $fid = $default_value;


    $query_result = db_query("SELECT cidade, endereco, estado 
                            FROM filial_pf
                            WHERE id_filial = '%d'",                           $fid);
    $row = db_fetch_object($query_result);
    $cidade = $row->cidade;
    $estado = $row->estado;
    $endereco = $row->endereco;

    $form['editar_filial']['cidade'] = array(
        '#type' => 'textfield',
        '#title' => "Nova Cidade da Filial",
        '#size' => 18,
        '#maxlength' => 18,
        '#required' => TRUE,
        '#default_value' => $cidade,
    );

    $estados = array(
                 "AC" => "AC",
                 "AL" => "AL",
                 "AP" => "AP",
                 "AM" => "AM",
                 "BA" => "BA",
                 "CE" => "CE",
                 "DF" => "DF",
                 "ES" => "ES",
                 "GO" => "GO",
                 "MA" => "MA",
                 "MT" => "MT",
                 "MS" => "MS",
                 "MG" => "MG",
                 "PA" => "PA",
                 "PB" => "PB",
                 "PR" => "PR",
                 "PE" => "PE",
                 "PI" => "PI",
                 "RJ" => "RJ",
                 "RN" => "RN",
                 "RS" => "RS",
                 "RO" => "RO",
                 "RR" => "RR",
                 "SC" => "SC",
                 "SP" => "SP",
                 "SE" => "SE",
                 "TO" => "TO");



    $form['editar_filial']['estado'] = array(
        '#type' => 'select',
        '#title' => "Estado",
        '#options' => $estados,
        '#required' => TRUE,
        '#default_value' => $estado,
    );

    $form['editar_filial']['endereco'] = array(
        '#type' => 'textarea',
        '#title' => "Novo Endereço da Filial",
        '#size' => 70,
        '#maxlength' => 140,
        '#required' => TRUE,
        '#default_value' => $endereco,
    );


$form['editar_filial']['salvar'] = array(
  '#type' => 'submit',
  '#value' => "Salvar",
);

return $form;
}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T18:59:37+00:00Added an answer on May 17, 2026 at 6:59 pm

    Made it work, found some nice examples here:

    http://www.kristen.org/content/drupal-ahah-form-examples

    And the code looks like this:

    function filiais_editar_form($form_state) {
    
        //
        // AHAH Helper stuff
        //
        $form = array();
        ahah_helper_register($form, $form_state);
    
    
        $form['editar'] = array(
            '#type'   => 'fieldset',
            '#prefix' => '<div id="editar-wrapper">', 
            '#suffix' => '</div>',
            '#tree'   => TRUE,
            );
    
        $query_result = db_query("SELECT DISTINCT ON (cidade) cidade, id_filial 
                                FROM filial_pf");
        $cidades = array();
        while($row = db_fetch_object($query_result))
            $cidades[$row->id_filial] = $row->id_filial . ' : ' . $row->cidade;
    
    
        if (!isset($form_state['values']['editar']['filial']))
            $choice = 0;
        else 
            $choice = $form_state['values']['editar']['filial'];
    
    
        $form['editar']['filial'] = array(
            '#type'             => 'radios',
            '#title'            => "Escolha a filial que deseja editar",
            '#options'          => $cidades,
            '#default_value'    => $choice,
            '#ahah' => array(
                'event'     => 'change',
                'path'      => ahah_helper_path(array('editar')),
                'wrapper'   => 'editar-wrapper',
                'method'    => 'replace',
            ),
        );
    
        $fid = $choice;
        if($fid != 0)
        {
            $query_result = db_query("SELECT cidade, endereco, estado 
                                    FROM filial_pf
                                    WHERE id_filial = '%d'", $fid);
            $row = db_fetch_object($query_result);
    
            $cidade = $row->cidade;
            $estado = $row->estado;
            $endereco = $row->endereco;
        }
        else
        {
            $cidade = '';
            $estado = '';
            $endereco = '';
        }   
        $form['editar']['cidade'] = array(
            '#type' => 'textfield',
            '#title' => "Nova Cidade da Filial",
            '#size' => 18,
            '#maxlength' => 18,
            '#required' => TRUE,
            '#default_value' => $cidade,
        );
    
        $estados = array(
            "AC" => "AC",
            "AL" => "AL",
            "AP" => "AP",
            "AM" => "AM",
            "BA" => "BA",
            "CE" => "CE",
            "DF" => "DF",
            "ES" => "ES",
            "GO" => "GO",
            "MA" => "MA",
            "MT" => "MT",
            "MS" => "MS",
            "MG" => "MG",
            "PA" => "PA",
            "PB" => "PB",
            "PR" => "PR",
            "PE" => "PE",
            "PI" => "PI",
            "RJ" => "RJ",
            "RN" => "RN",
            "RS" => "RS",
            "RO" => "RO",
            "RR" => "RR",
            "SC" => "SC",
            "SP" => "SP",
            "SE" => "SE",
            "TO" => "TO");
    
        $form['editar']['estado'] = array(
            '#type' => 'select',
            '#title' => "Estado",
            '#options' => $estados,
            '#required' => TRUE,
            '#default_value' => $estado,
        );
    
        $form['editar']['endereco'] = array(
            '#type' => 'textarea',
            '#title' => "Novo Endereço da Filial",
            '#size' => 70,
            '#maxlength' => 140,
            '#required' => TRUE,
            '#default_value' => $endereco,
        );
    
    
        $form['editar']['salvar'] = array(
          '#type' => 'submit',
          '#value' => "Salvar",
        );
    
        $form['#redirect'] = '';
    
      return $form;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to loop through a bunch of documents I have to put
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm making a simple page using Google Maps API 3. My first. One marker
I have some data like this: 1 2 3 4 5 9 2 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.