How to pass a variable from one function to another function?

Events happening in the community are now at Drupal community events on www.drupal.org.
Posted by jessSchn on October 12, 2012 at 8:32pm

On a Drupal 6 Website I am trying to accomplish the following:

On a node (page), I want to pull the node title and then I want to send the node title over to a webform that is displayed as a block on the same page, as a hidden field.

Here is what I have so far:

//currently being done inside a custom module - not sure how else to code it

//get node information
function customform_nodeapi(&$node, $op, $teaser, $page){
switch($op){
case 'view':
if ($node->type == "recorded_webinars"){
$cf_node_title = $node->title;['value'];
}
break;
}//end switch
}

//place node information in hidden field on form block
function customform_form_webform_client_form_9232_alter($form, &$form_state,$form_id) {// on-demand webinar request form.

$form['webinar_title'] = array(
'#title' => t('On Demand Webinar Title'),
'#type' => 'hidden',
'#value' => $cf_node_title
);
}

To my understanding - the hook_nodeapi function works. The only thing not working on the hook_form_alter() is the value.

How do I pass the $cf_node_title value over to the hook_form_alter() function?

Categories: ,

Comments

In function

Posted by JBack on October 12, 2012 at 9:01pm

In function customform_form_webform_client_form_9232_alter

//place node information in hidden field on form block
function customform_form_webform_client_form_9232_alter($form, &$form_state,$form_id) {

// on-demand webinar request form.
$form['webinar_title'] = array(
'#title' => t('On Demand Webinar Title'),
'#type' => 'hidden',
'#value' => $node->title
);
}

The $node object is "global", meaning all functions can see it.

tried that...

Posted by jessSchn on October 12, 2012 at 9:22pm

Thanks for the response, but I had already tried that and my value wasn't getting filled in - it was just blank.

Whoops!

Posted by JBack on October 12, 2012 at 10:14pm

Sorry,
didn't realize you were using form_alter, and that the $node in your previous function was being passed in.

This is a good use case for devel, where kpr($form) may help you out.
Regardless, I did a little googling, and came up with this thread...

http://drupal.org/node/183872
This is how they got it...

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

Hope that helps, sorry for the runaround.

Close but no cigar :)

Posted by jessSchn on October 15, 2012 at 1:24pm

So I gave the code you provided a try and I did get the hidden value set. But - the hidden value had the title of the webform (that is displayed as a block), I'm trying to get the Page title (that displays the block) into the hidden value - not the webform title. :/

Solved!

Posted by jessSchn on October 15, 2012 at 2:42pm

Here is what I ended up doing in my module to get the page title sent to the webform block:

function customform_nodeapi(&$node, $op, $teaser, $page){
global $cf_node_title;

switch($op){
case 'view':
if ($node->type == "recorded_webinars"){
$cf_node_title = $node->title;
}
break;
}//end switch

}

//place node information in hidden fields on form block
function customform_form_webform_client_form_9232_alter($form, &$form_state,$form_id) {

global $cf_node_title;

$form['webinar_title'] = array(
'#title' => t('On Demand Webinar Title'),
'#type' => 'hidden',
'#value' => $cf_node_title
);

}

Twin Cities

Group events

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

AltStyle によって変換されたページ (->オリジナル) /