Hello,

I am trying to display the user contact form at the bottom of certain node-types (flexinode), so that the visitor can easily contact the service provider they are after.

I am using code from this post: Including another page in your node (or another page)

I am using this code in my flexinode-1.tpl.php

<?php
// We save and restore the real path for the page
$q = $_GET['q'];

// Get and print the output for just the content associated with the path
$contact="user/".$node->uid."/contact";
print ($contact);
$_GET['q'] = drupal_get_normal_path($contact);
print menu_execute_active_handler();

// Restore the real path for the page
$_GET['q'] = $q;
?>

What I get when I do this is the user's information (user/X), rather than that user's contact form (user/X/contact). If I paste this code into the body of a php page, it works fine.

In my flexinode-1.tpl.php, the print statment above just shows that yes, I'm getting the correct path "user/X/contact"

I get the same result if I change "contact" to "tracker".

I know that if you type "user/X/oops-invalid-path", you get "user/X", so I think it's related.

Any ideas?

Thanks,

Tys.

Comments

nevets’s picture

Snippet does not work because it is a tab that depends on the current path, the result being that the path you want is not even defined at this point. You could try the following

<?php
// We save and restore the real path for the page
$q = $_GET['q'];

// Get and print the output for just the content associated with the path
$contact="user/".$node->uid."/contact";
print ($contact);
$_GET['q'] = drupal_get_normal_path($contact);
print contact_mail_user();

// Restore the real path for the page
$_GET['q'] = $q;
?>

which may work (I have not tried it). You still need to set $_GET['q'] because contact_mail_user() relies on arg(1).

tyswan’s picture

That works fine, but I seem to have another problem.

I guess I don't really understand the guts of Drupal & how it serves data.

I used the snippet you suggested.

Curiously the "title" of the entire page is now the user's name (ie. the title of user/X/contact)

It seems that whilst the snippet is at the bottom of the page, the $title value is "printed" later and that this is affected by the snippet temporarily pulling another page in (and perhaps messing up all the page variables).

Your thoughts on how I do this in a more robust way?

Thanks,
--
tys

BLUE MOUNTAINS health & harmony
www.health-harmony.com.au

building an alternative health & spirituality community in the Blue Mountains

nevets’s picture

Change

print contact_mail_user();

to

$title = drupal_get_title();
print contact_mail_user();
drupal_set_title($title);
tyswan’s picture

I tried saving & restoring the title ($title=$savetitle), but it didn't work.

Your solution is great. One day I'm going to figure out how drupal really works...

Thanks for helping me out.

Cheers,
--
tys

BLUE MOUNTAINS health & harmony
www.health-harmony.com.au

building an alternative health & spirituality community in the Blue Mountains

bernardwright’s picture

I have a flexinode and want to do the same, use the default theme listing but when viewing the flexinode in detail show the contact form at the bottom of the page. I did the above and added it to flexinode-1.tpl.php and uploaded but nothing happened no contact form. However if I created node-flexinode-1.tpl.php then only the contact form appears as I expected this overrides everything.

I cannot get the contact form to be inserted into an existing page. Any suggestions?

Thanks