Hello guys,

first i want to apologize my bad english. :)

I have a big problem with a modules that I develope within the last days.

I implement in my first module the hook_form with a textfield and a submit button, in my second module I implement the hook_form too with a select box.

The selected value from the select box in the second module is to be submitting with the submit button from the first module.

Have anyone of you a answer for this problem or a approach?

Thanks in advance.

Chris

Comments

nevets’s picture

What is the purpose of the forms, hook_form() is used by modules when they implement a content type. They would use hook_insert()/hook_update() to save the data. Since those functions are only called for the module that implements a content type it is not clear how you problem is occurring.

NGC1981’s picture

Thanks nevets for the fast answer.

I use the hook_form() in a block, is this wrong?

I try to explain it better:
I have in my first module a block with a texfield and a submit button, this is the default view for the block.
Now I add with my second module and my own hook_ another forms in the same block e.g. a select box prefilled with data from my database.
When I activate the modules and the block I can see the prefilled select box, the textfield and the submit button, but if I click the submit button they only saved the data from the textfield and not the selected value from the select box.

I hope this entry makes it a little bit clearly.

Chris

nevets’s picture

hook_form() is used by modules that implement a content type, it is not meant to be called directly by other code.

When you say "Now I add with my second module and my own hook_ another forms in the same block" it makes me wonder what you are trying to do. Two modules can not manipulate the same block. Also, one module can implement more than one block so I wonder why you have two modules.

How are you prefilling the select box, what does the code look like?

NGC1981’s picture

Okay here comes the code from my second module, this module represents a sport centre with teams and anything, is just a demo module to test the
another module.

function demo_teams_form($args){

	$res = db_query("SELECT * FROM {demo_teams}");
	
	while($data = db_fetch_object($res))
	{
		$teams[] = $data->teams;
	}
	
	$form['homeTeams'] = array(
		'#type' => 'select',
		'#title' => t('Home team'),
		'#options' => $teams,
	);
	
	$form['guestTeams'] = array(
		'#type' => 'select',
		'#title' => t('Guest team'),
		'#options' => $teams,
	);
	return $form;
}

Here i prefill the select box with the data from the database.

Now my "hook_" implementation, I call it hook_pane()


function demo_teams_pane(){

	$pane['teams_pane'] = array(
		'id' => 'demo-teams',
		'callback' => 'drupal_get_form',
		'callback arguments' => array('demo_teams_form'),
	);

	return $pane;
}

Here i give my pane a callback with 'drupal_get_form' and a callback argument which call the form from the module.

Now the another module who represent the default form and first my hook declaration, this declaration works really fine.

function render_input_panes(){

	$panes = module_invoke_all('pane');
	
	foreach($panes as $key => $pane)
	{
		$args = array();
		$prefix = $pane['prefix'] ? $pane['prefix'] : NULL;
		$suffix = $pane['suffix'] ? $pane['suffix'] : NULL;
		$class = $pane['attributes']['class'] ? '<div class="' . $pane['attributes']['class'] . '">' : '<div>';
		
		if($pane['callback'])
		{
			$func = $pane['callback'];
			
			if(!empty($pane['callback arguments']))
			{
				$args = $pane['callback arguments'];
			}

			if($pane['callback'] == 'drupal_get_form')
			{
				$form_ids[] = $pane['callback arguments'][0];
				$args['form_ids'] = $form_ids;
				$pre_render = $prefix . $class . $func($args[0]) . $suffix . '</div>';
			}

			if($pane['theme'])
			{
				$o[$pane['id']] = theme($pane['theme'], $pre_render);
			}
			else
			{
				$o[$pane['id']] = $pre_render;
			}
		}
	}
	return theme('pane', $o);
}

And here is the default form too.

function report_submit_form($form_ids){
	
	$form['report'] = array(
		'#type' => 'textarea',
		'#title' => t('Report'),
	);
	
	$form['submitReport'] = array(
		'#type' => 'submit',
		'#value' => t('Submit report'),
	);
	
	return $form;
}

I hope this helps.

Chris

nevets’s picture

My first thought is why not use the panels module?

Your question is not about blocks or even Drupal standard functionality and it is not at all clear what your actual problem is.

kasalla’s picture

Heyho,

he wants to use a single submit handler for multiple forms.

form_1 (from module a)
form_2 (from module b)
(both are on the same page/block, no wizard, multistep or something)

one submit handler for both forms.

(formerly anstosser)
DOMAIN anstoss.de FOR SALE
Kasalla Media :: www.kasalla-media.de