I'm trying to change the way my node/add form redirects because at the moment when a user submits a "create new node" form they are redirected to the custom page.tpl that I have created, but with no content shown. They don't get any way provided to get back to the admin interface apart from their back button.

So what I want to do is create a function in the template.php file so I can change the #redirect element of the form. But baby steps first, I'm just trying to add a string of text into the top of it to start with so I know I'm targeting the form;

function mythemename_theme() {
	return array(
    'product_node_form' => array
	(
      'arguments' => array('form' => NULL),
    ),
  );
}

function mythemename_product_node_form($form){
	$output = '<h1>TEST</h1>';
	$output .= drupal_render($form);
	return $output;
	}

But it doesn't seem to do anything to the form.

Any ideas?

TIA

Comments

theabacus’s picture

If you want to change the #redirect value, do it from hook_form_alter() in a custom module.

markosaurus’s picture

So looking atthe api for hook_form_alter I see that it says;

Note that instead of hook_form_alter(), which is called for all forms, you can also use hook_form_FORM_ID_alter() to alter a specific form.

I want to do this with any node add form eventually but for now I'm concentrating on one (it has the id of product_node_form).

This is what I have in my new module that I created called newnode_redirect, which is enabled.

function hook_form_product_node_form_form_alter(&$form, $form_state, $form_id) 
{
	if( $form['#redirect'] == "node-form" )
	{
		//$form['#redirect'] = $_SERVER['HTTP_REFERER'];
		$form['#redirect'] = '/node/add';
	}
}

Can you see anything wrong with that? And what else do I need to do to call this function? I was under the impresion that it would be called when the hook_form_product_node_form was invoked?

Thanks loads for helping.

EDIT;

IT was me being stupid as usual, did a bit of poking around and managed to get it working in a rudimentary form by using this ;

/**
* Implementation of hook_form_alter
*/

function newnode_redirect_form_alter(&$form, $form_state, $form_id) {
    
	if($form_id == 'product_node_form'){
					
		$form['#redirect'] = '/node/add';
		
		}

}

Thanks for your help.