1

I'm new at Drupal CMS and programming at all, but I'm trying to find my way to solve this problem.Unfortunately unsuccesful for now. I've installed Drupal 7.5 and Multipurpose theme which has social icons to redirect to facebook,twitter and etc.In theme settings there is an option to paste link with profile.I wanted to tweak their function a bit but I'm stuck with the code int the page.tpl.php file. What I'm trying to do is basicly to check if the user is logged in, and if he is and a link was given in the setting of the theme to redirect to the social profile.The problem occurs when the user presses the button twice or more because the link copies over and over instead of refresh...for example: 1 click: https://www.facebook.com/user and on the 2 click becomes: https://www.facebook.com/user/user and so on. The code:

 <?php if (!$logged_in) : ?>
      <?php if ($twitter_url): ?><li>
        <a title="<?php print $site_name; ?> in Twitter" href="<?php print $twitter_url; ?>"><img alt="Twitter" src="<?php print base_path() . drupal_get_path('theme', 'multipurpose') . '/images/social/twitter.png'; ?>"> </a> <?php endif; ?>
      </li><?php endif; ?>

So the question is how can I disable the button(become inactive not hidden) after one click or is there any other approach to solve this problem? Thank you!

  • Your question mentions Facebook but the code shows Twitter. If the URL is absolute (http://...) it should work fine. What do you mean the link copies over and over instead of 'refresh'? It is an external link right? – Kevin Mar 15 '17 at 18:04
  • Ok to be honest I'm trying to use this code but for calling the login page :D The code is absolutly the same but instead of facebook link I'm using user/login and it does call the log page but before I log if I press the button again and again the problem occurs.I know it strange method but I have alredy written code and it's easier for me due to the lack of programming skills.... – htopalov Mar 15 '17 at 18:11
  • The login page to what? Drupal? In that case the href is just '/user/login'. – Kevin Mar 15 '17 at 18:11
1

The link needs a slash in front of it:

/user/login

instead of:

user/login

Logout would be:

/user/logout

You need to use relative paths or you will continue encountering this behavior. A better way would be to send the variables to your template(s) via the appropriate preprocess function, and use the l() function to create links.

  • ohhhhhh it works....is this the same logic for logout – htopalov Mar 15 '17 at 18:20
  • @htopalov If it works please mark this answer as correct. – sanzante Mar 15 '17 at 18:21
  • Thank you very much...I've been trying to solve this problem all day long and it is simple as that – htopalov Mar 15 '17 at 18:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.