My form includes several statements from the database, which are generated randomly, ie every time there are new (something like a test). And i need to remember current values, but in &form i can't get the right ones, there are allways updated ones. How can i fix it?

function mudule_form(&$form_state){
.....
$all = array(
'one' => $st[0],
'two' => $st[1],
......
);

$form['questions'] = array(
'#type' => 'checkboxes',
'#title' => t('...'),
'#options' => $all
);
$form['sub_but'] = array(
'#type' => 'submit',
'#value' => t('....')
);
return $form;
}

function module_form_submit($form, &$form_state) {
print_r($form); // i don't see here the statements that i saw before "submit", there are new generated statements
die("\n
DIE");
}

Comments

nitin.k’s picture



// function mudule_form(&$form_state){ // Incorrect definition

function mudule_form($form, $form_state) { // Although not necessary to pass the arguments but pass for future use.

.....
$all = array(
'one' => $st[0],
'two' => $st[1],
......
);

As far as statements are concerned you need to check code versions of file.

Jaypan’s picture

That should be:

function module_form($form, &$form_state) {

$form_state needs to be a reference.

nitin.k’s picture

Absolutely correct , Missed the reference !!

Anonymous’s picture

I am very grateful!!:)

Anonymous’s picture

but now i get only white screen after 'submit'... function module_form_submit do nothing... =/ the error is: Cannot use string offset as an array in ../drupal/includes/form.inc on line $form[$key]['#post'] = $form['#post'];

Jaypan’s picture

You shouldn't be doing anything with POST data - Drupal handles that for you.

It seems you are missing some fairly core concepts of the Drupal Form API. You'd probably be best spending some time doing some research on the Form API and then come back to your form.