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?
Comments
In function
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...
Thanks for the response, but I had already tried that and my value wasn't getting filled in - it was just blank.
Whoops!
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 :)
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!
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
);
}