Newbie here, as learning process, i'm creating a module that collect data from the user then insert them into the db, but i can't figure out how to get the content of the form varible . This is the function that displays the form to the user

/*** This is a callback funtion actually ****/
function display_form()
   $index_lang = index_lang();
    $output = '<h2>'.t('Add New Entry').'</h2>';
     
    $form = form_textfield( t('Language'),'dictname',
                             '',50,50,'Enter new language',
                             $required = TRUE 
                            );
    $form .= form_select( t('Index language'),'indexlang',
                           key($index_lang), $index_lang, 
                           t( 'Select the index language of the 
                               new language') 
                        );
     
    $form .= form_radios( t('Status'), 'status',
                           '',array('status' => t('On'),t('Off'))
                          );
                  
    $form .= form_submit( t( 'Add Entry' ) ); 
    $output .= form( $form );
   print theme( 'page', $output );
}

Please help on how to get the content of the form element when the user clicks on the submit button.

Comments

nevets’s picture

You need to add something like the following before the begining of function code.

function display_form() {
  $edit = $_POST['edit'];
  $op = $_POST['op'];

  if ( $edit && $op == t('Add Entry') ) {
    // Do something with the data
    // You can retrieve the data as
    // $edit['dictname'], $edit['ndexlang'], etc

   // If you do not want the form redisplayed
  // you will want to call drupal_goto()
  }

   // Build and display the form
   ...
}
eyedol’s picture

please how do i get the actual value of the select element. i realise i get the key of it. Thanks.

nevets’s picture

Once you have $edit you can get the value like

$value = $edit['indexlang'];
eyedol’s picture

ok thanks for the help, what i actually want from the select element is the is string value of the select element not the key value element. To explain further,
the options for the select element are
English
Spanish
Arabic

but when i insert the value into the db is numbers. Base on what i select i get its number. say if i select Spanish i get 1 stored in the db. i want to store what i select into the db so in this case Spanish should be stored.

nevets’s picture

Make sure the line "$index_lang = index_lang();" is before the 'if' checking $edit and $op. Then after you get the value

$lang_str = $index_lang[$value];

should get you the string value.

eyedol’s picture

I tried that but it gave me empty string

nevets’s picture

In the code right after you get the value try this

drupal_set_message("Value = $value");
drupal_set_message(print_r($index_lang, TRUE));

This will show the value plus the array members when you submit. I would expect the value to be one of the keys in $index_lang but it sounds like it is not which is unexpected.
If the output does not help and you want you can post it here.

eyedol’s picture

This is what i got
the output:

    Value = yes
   Array ( [0] => English [1] => French [2] => Abrabic [3] =>   Portuguese [4] => Spanish )
eyedol’s picture

I manage to solve it by using the selected key to determine the actuall value. the code is this


$lang_str = $lang[$edit['indexlang']]

nevets’s picture

A value of 'yes' does not make sense with the code you have shown. Is it possible for you to share a url to a page with the form (if you don't want it public you could always email me through my contact tab). Also seeing the latest complete copy of the function would be useful.