How do I replace Registration link with a button?

Permalink Browser Info Environment
Hi,

I have managed to get the Login block working as a Trade Only sign in to a website I am creating for a client. The login works and the register link goes to my styled register page to collect the input details to create user.

Last little thing I was to do is change the register link text for a button. I have attached a screen of what currently is there, I want a same styled button underneath Trade Login, simply saying 'Register'.

I feel a button for each option is better.

Here is the code from my view.php
<?php   defined('C5_EXECUTE') or die(_("Access Denied.")); 
$c = Page::getCurrentPage();
$u = new User();
$loginURL= $this->url('/login', 'do_login' );
if ($u->isRegistered() && $hideFormUponLogin) { ?>
   <?php    
   if (Config::get("ENABLE_USER_PROFILES")) {
      $userName = '<a href="' . $this->url('/profile') . '">' . $u->getUserName() . '</a>';
   } else {
      $userName = $u->getUserName();
   }
   ?>
   <span class="sign-in"><?php   echo t('Currently logged in as <b>%s</b>.', $userName)?> <a href="<?php   echo $this->url('/login', 'logout')?>"><?php   echo t('Sign Out')?></a></span>
<?php    } else { ?>   
   <form class="login_block_form" method="post" action="<?php    echo $loginURL?>">


Thanks

Nick

1 Attachment

Type: Discussion
Status: Archived
pixeleleven
View Replies: View Best Answer
mkly replied on at Permalink Best Answer Reply
mkly
Hello,
Often people style anchor links("<a href=") with css to make the into buttons. If you prefer not to go down that route you can do this(requires javascript)
<button onclick="window.location = '<?php echo View::url('/register')?>'"><?php echo $registerText?></button>


Just replace the register link with that and you should now have a button.

Best Wishes,
Mike
pixeleleven replied on at Permalink Reply
pixeleleven
Thanks Mike, worked a treat ;o)

Best Regards
Nick
mkly replied on at Permalink Reply
mkly
Good news.

Best Wishes,
Mike
pixeleleven replied on at Permalink Reply
pixeleleven
Hi Mike,

Sorry, I spoke too soon. I have the register button sitting below the Trade LogIn button, but where the Trade Log in points to a trade area on successful log in. The Regsiter button also clicks through to the Trade Area, which it should not, it is meant to go to my Register page.

Here is my code.

Previously the text link went to the register page and trade login button when successful details were entered took you to a Trade Area.

Now they both hit the same place?

<?php   defined('C5_EXECUTE') or die(_("Access Denied.")); 
$c = Page::getCurrentPage();
$u = new User();
$loginURL= $this->url('/login', 'do_login' );
if ($u->isRegistered() && $hideFormUponLogin) { ?>
   <?php    
   if (Config::get("ENABLE_USER_PROFILES")) {
      $userName = '<a href="' . $this->url('/profile') . '">' . $u->getUserName() . '</a>';
   } else {
      $userName = $u->getUserName();
   }
   ?>
   <span class="sign-in"><?php   echo t('Currently logged in as <b>%s</b>.', $userName)?> <a href="<?php   echo $this->url('/login', 'logout')?>"><?php   echo t('Sign Out')?></a></span>
<?php    } else { ?>   
   <form class="login_block_form" method="post" action="<?php    echo $loginURL?>">


Any ideas?

Many Thanks

Nick
mkly replied on at Permalink Reply
mkly
Hello,
One this I noticed is that you placed in a way that likely caused a php error. It like should be inside that if statement.
<?php     if($showRegisterLink && ENABLE_REGISTRATION){ ?>
  <div class="login_block_register_link"><a href="<?php    echo View::url('/register')?>"><?php    echo $registerText?></a></div>
<?php     } ?>


Notice the bracket there at the end? Let's start with that and see where it gets us.

Also, make sure to have "Public Registration" enabled in the dashboard.

Best Wishes,
Mike
pixeleleven replied on at Permalink Reply
pixeleleven
Hi Mike,

Thanks for looking at this, I am not really up to date with PHP ;o(

But I stuck your amended code into the page and I am still not getting that button up.

Here is exactly the code I have in there

<?php   defined('C5_EXECUTE') or die(_("Access Denied.")); 
$c = Page::getCurrentPage();
$u = new User();
$loginURL= $this->url('/login', 'do_login' );
if ($u->isRegistered() && $hideFormUponLogin) { ?>
   <?php    
   if (Config::get("ENABLE_USER_PROFILES")) {
      $userName = '<a href="' . $this->url('/profile') . '">' . $u->getUserName() . '</a>';
   } else {
      $userName = $u->getUserName();
   }
   ?>
   <span class="sign-in"><?php   echo t('Currently logged in as <b>%s</b>.', $userName)?> <a href="<?php   echo $this->url('/login', 'logout')?>"><?php   echo t('Sign 
Out')?></a></span>
<?php    } else { ?>


Plus, yes I have public registration enabled ;o)

Thanks

Nick
mkly replied on at Permalink Reply
mkly
I copy and pasted the other link. See how that one had an a tag in it?

should be the button code

<button onclick="window.location = '<?php echo View::url('/register')?>'"><?php echo $registerText?></button>
pixeleleven replied on at Permalink Reply
pixeleleven
Hi Mike,

I have been tinkering around with this and your suggestions.

This is the final code I put in that view.php for the login and I get a Registration Button alright.

<?php   defined('C5_EXECUTE') or die(_("Access Denied.")); 
$c = Page::getCurrentPage();
$u = new User();
$loginURL= $this->url('/login', 'do_login' );
if ($u->isRegistered() && $hideFormUponLogin) { ?>
   <?php    
   if (Config::get("ENABLE_USER_PROFILES")) {
      $userName = '<a href="' . $this->url('/profile') . '">' . $u->getUserName() . '</a>';
   } else {
      $userName = $u->getUserName();
   }
   ?>
   <span class="sign-in"><?php   echo t('Currently logged in as <b>%s</b>.', $userName)?> <a href="<?php   echo $this->url('/login', 'logout')?>"><?php   echo t('Sign Out')?></a></span>
<?php    } else { ?>   
   <form class="login_block_form" method="post" action="<?php    echo $loginURL?>">


But the really odd thing is that the Register Button when clicked it takes you to the login page, which I don't want. The link in the php ech View is right, but it seems the view.php code above is creating a duplicate login button in the new Register Button.

Do I need to add some code elsewhere is the block?

Thanks

Nick
mkly replied on at Permalink Reply
mkly
Hello,
It's possible the button is submitting the form. Try adding type = button
<button type="button" onclick="window.location = '<?php echo View::url('/register')?>'"><?php echo $registerText?></button>


Best Wishes,
Mike
pixeleleven replied on at Permalink Reply
pixeleleven
Thanks Mike, that worked perfectly.

Thanks again for all your great input.

Kind Regards


Nick
mkly replied on at Permalink Reply
mkly
Heh, finally. Glad to hear we got it sorted out. I should have realized that button would submit the form if I didn't explicitly set it to type="button". Lesson learned.

Best Wishes,
Mike
pixeleleven replied on at Permalink Reply 1 Attachment
pixeleleven
Hi Mike,

I think I broke it!...

The client wanted to have the Register button in red and Log In button in Blue. So I thought it would be easy to call in Bootstrap colours on the above and realised I am not so clever.

Sorry to drag up again, but wonder if you can help me ;o)

To recap the block is the standard Login block used, clicking Login with a valid email and password allows entry to a hidden section on website. Click to Register, takes you to the personalised 'Register' page I have created and held in 'single pages''

Here is the view.php for that block with what I have done.

<?php   defined('C5_EXECUTE') or die(_("Access Denied.")); 
$c = Page::getCurrentPage();
$u = new User();
$loginURL= $this->url('/login', 'do_login' );
if ($u->isRegistered() && $hideFormUponLogin) { ?>
   <?php    
   if (Config::get("ENABLE_USER_PROFILES")) {
      $userName = '<a href="' . $this->url('/profile') . '">' . $u->getUserName() . '</a>';
   } else {
      $userName = $u->getUserName();
   }
   ?>
   <span class="sign-in"><?php   echo t('Currently logged in as <b>%s</b>.', $userName)?> <a href="<?php   echo $this->url('/login', 'logout')?>"><?php   echo t('Sign Out')?
></a></span>
<?php    } else { ?>


I also attach a screenshot of how my mess looks, with the description below I hope this helps ;o)

The Blue Log In button for some reason has two buttons over the top of each other, but it correctly allows log in when the right details are entered in fields and clicked.

The Red Register button looks quite right, but when clicked it goes wrongly to the login page and not register.php

Thanks

Nick
mkly replied on at Permalink Reply
mkly
Code
<?php   defined('C5_EXECUTE') or die(_("Access Denied.")); 
$c = Page::getCurrentPage();
$u = new User();
$loginURL= $this->url('/login', 'do_login' );
if ($u->isRegistered() && $hideFormUponLogin) { ?>
   <?php    
   if (Config::get("ENABLE_USER_PROFILES")) {
      $userName = '<a href="' . $this->url('/profile') . '">' . $u->getUserName() . '</a>';
   } else {
      $userName = $u->getUserName();
   }
   ?>
   <span class="sign-in"><?php   echo t('Currently logged in as <b>%s</b>.', $userName)?> <a href="<?php   echo $this->url('/login', 'logout')?>"><?php   echo t('Sign Out')?
></a></span>


Hello, take a look at the bottom part of this code. Instead of using the form helper $form->submit we're replacing it with a basic input type="submit" and the bottom button for register had bbtn not btn. Hopefully that will give you some insight into the issue.

Best Wishes,
Mike
pixeleleven replied on at Permalink Reply
pixeleleven
Hi Mike,

Thanks for the speedy reply.

The bbtn comes from the bootstrap button style name I copied and pasted, they were like that, I took out the extra 'b' and the whole thing did not work at all.

Still really puzzled ;o(

Nick
pixeleleven replied on at Permalink Reply
pixeleleven
Sorry Mike,

Been tinkering with this all day, cannot get it right. Sorry to ask again, but I really have no idea here on what I am to be changing to get this right.

I have now added the styling for those two divs nurseryregbutt and nurserytradebutt, so they are now sitting away from the left.

But that is the best of my limited ability.

Regards

Nick
mkly replied on at Permalink Reply
mkly
Hello,
You were placing a button around an submit button. You cannot do this in HTML.
<button>
<?php echo $form->submit('some_button', t('Update')) ?>
</button>


You need to change this to simply be an html submit button with not <button> around it. Get rid of the form->sbumit etc and just have this

<input class="btn btn-primary" type="submit" />


Hope that makes a bit more sense.

Best Wishes,
Mike
pixeleleven replied on at Permalink Reply
pixeleleven
Hi Mike,

Thanks for the reply, sorry for the panicky post. I did a little tinker after some more coffee, right after I posted and came up with this....

<?php   defined('C5_EXECUTE') or die(_("Access Denied.")); 
$c = Page::getCurrentPage();
$u = new User();
$loginURL= $this->url('/login', 'do_login' );
if ($u->isRegistered() && $hideFormUponLogin) { ?>
   <?php    
   if (Config::get("ENABLE_USER_PROFILES")) {
      $userName = '<a href="' . $this->url('/profile') . '">' . $u->getUserName() . '</a>';
   } else {
      $userName = $u->getUserName();
   }
   ?>
   <span class="sign-in"><?php   echo t('Currently logged in as <b>%s</b>.', $userName)?> <a href="<?php   echo $this->url('/login', 'logout')?>"><?php   echo t('Sign Out')?></a></span>
<?php    } else { ?>   
   <form class="login_block_form" method="post" action="<?php    echo $loginURL?>">


Which seemed to work also...

I will also try your suggestion now.

Best Regards

Nick
ConcreteCMS replied on at Permalink Reply
ConcreteCMS
Attention: Since there has been no activity on this issue for two weeks, this issue has been automatically archived.

To re-open this issue, reply to this message.

concrete5 Environment Information

Browser User-Agent String

Hide Post Content

This will replace the post content with the message: "Content has been removed by an Administrator"

Hide Content

Request Refund

You have not specified a license for this support ticket. You must have a valid license assigned to a support ticket to request a refund.