usmanz
05-20-2009, 01:58 PM
Hi,
I am using a built-in feature of Drupal where you can pass a PHP code based value in URL.
I am using the following format:
<a href="http://acheapwebdesign.com/orderform?product=<?php print $node->title; ?>">Order Now</a>
But it is not passing anything in place of PHP code, it IS passing whatever I specify statically.
Can anyone help?
foobic
05-20-2009, 07:03 PM
But it is not passing anything in place of PHP code, it IS passing whatever I specify statically.By this do you mean you've tried something like <?php print "hello"; ?> and it works, but $node->title is empty? $node isn't available in all situations - are you trying to use this code in the body of the page, perhaps? If so, this (http://drupal.org/node/110845) may give you some hints.
I'd suggest you explain in detail what you're trying to do - there may well be a better way to achieve it.
usmanz
05-21-2009, 07:46 AM
By this do you mean you've tried something like <?php print "hello"; ?> and it works, but $node->title is empty? $node isn't available in all situations - are you trying to use this code in the body of the page, perhaps? If so, this (http://drupal.org/node/110845) may give you some hints.
I'd suggest you explain in detail what you're trying to do - there may well be a better way to achieve it.
What I meant by passing static value was:
product=product_name (without php code)
You have given a good idea of using product=<?php print "hello"; ?> . It is working. I will use this method to print title in case I fail to print it using PHP.
And yes I'm using this code in body of a node, but it's a single node, not in a block form. You can see it here:
http://acheapwebdesign.com/testtemplate5
The place where I am trying to use php code is the "Order Now" link below image.
Thank you for your interest.
usmanz
05-21-2009, 08:01 AM
HEYYY!
When I followed whats described in your link, it worked for me!
I'm surprised when I searched for it in Drupal's website I couldn't find it. I even posted it in Drupal's forums but did not get anything that works. I'm glad I found its solution through WHT :cool:
What I have done is, I have written the following code in place of the value of parameter to be passed through the link:
<?php if ( arg(0) == 'node' && is_numeric(arg(1)) && ! arg(2) ) { $node = node_load(arg(1));} print $node->title; ?>
So if the title of node is "Test Template", it will print this URL:
<a href="http://acheapwebdesign.com/orderform?product=Test Template">Order Now</a>
Thanks for your help, this was the final blocking issue in my whole Drupal project.
foobic
05-21-2009, 08:11 AM
That's the wrong way to do it though, unless you really have no choice.
If you put the link into the node template you're using (instead of the page content) your original code should work. Try editing node.tpl.php in your theme directory and putting your code in there just below the content. You'll also need to urlencode (http://au.php.net/manual/en/function.urlencode.php) the title, either way.
usmanz
05-21-2009, 08:48 AM
When you say its the wrong way to do it, is there any security issue with this?
I (site admin) will be the only one to add or edit that field, is it OK then?
foobic
05-21-2009, 05:58 PM
No, it's not about security (though you should certainly consider that also), just about choosing the most appropriate / efficient / maintainable way to achieve a result.
In this case you have a special type of content you want formatted with title at the top, body in the middle and title again (formatted as a link) at the bottom. IMO, the correct way to do that is in the template. The advantages are:
you only have to set this up once for all pages of this type
if you change the format in future, you'll only need to change it in one place instead of editing every page
you don't need to enable PHP processing on the content
But it's your choice. ;)