Hello Forum,

When I need to capture the title of the node i am working on i can do this:

$title = ($node->title);

but in in form_alter that doesn't work. So how do i capture the title (or any node object) of the noide i am submitting?

I have searched but am not looking in the right places obviously!

Thank you in advance

Comments

local’s picture

form_alter takes $form_id and $form as arguments, so try $form['title']?

stclaird’s picture

$node = $form['#node'];
$title= $node->title;

I knew it was in there somewhere after getting the 'Form Inspect Module'!

Thank you

tejaspmehta’s picture

Hello,

I am using drupal 6 and i have same question. i am also trying to print title using form_alter() method but its not helping me out. here is code

function textchange_form_alter(&$form, &$form_state, $form_id)
{
	switch($form_id){
		case 'signup_form':
		 $node = $form['#node'];
		 $title= $node->title;
		 $form['collapse']['#title'] = t("Click here to ".$title);
		break;
	}
}

can you let me know what is wrong here ? i am trying to search on document but not getting solution.

jaypan’s picture

'signup_form' isn't a node type, so the node object won't exist.

Contact me to contract me for D7 -> D10/11 migrations.