Fork me on GitHub
Current releases are 2.1.1 (2 Aug 2014) and 2.0.18.13 (5 Aug 2014)
Ready for 2.1? Find out if your favorite plugins are compatible.
The 2.0 branch will no longer receive updates after Dec 2014.

sign in box built into page

edited May 2012 in Vanilla 2.0 Help

Hi Guys, I have a custom homepage (using custom pages plugin) and I would like to have the stuff that pops up in the signin window (username and password boxes, sso button, etc) built into my homepage in a div at the top. Just wonder how I would do this this (my php isn't great im still learning)?

Best Answer

  • x00x00 MVP
    edited May 2012 Answer ✓

    Basically adapting the existing form.

    <div>
       <?php
       $Form = Gdn::Factory('Form');
       echo $Form->Open(array('Action' => $this->Data('FormUrl', Url('/entry/signin')), 'id' => 'Form_User_SignIn'));
       //echo $Form->Errors();
       ?>
       <ul>
          <li>
             <?php
                echo $Form->Label('Email/Username', 'Email');
                echo $Form->TextBox('Email');
             ?>
          </li>
          <li>
             <?php
                echo $Form->Label('Password', 'Password');
                echo $Form->Input('Password', 'password', array('class' => 'InputBox Password'));
                echo Anchor(T('Forgot?'), '/entry/passwordrequest', 'ForgotPassword');
             ?>
          </li>
          <li class="Buttons">
             <?php
                echo $Form->Button('Sign In');
                echo $Form->CheckBox('RememberMe', T('Keep me signed in'), array('value' => '1', 'id' => 'SignInRememberMe'));
             ?>
          </li>
       </ul>
       <?php
       echo $Form->Close();
       ?>
    </div>
    

    grep is your friend.

    slaretibartfast

Answers

  • aeryaery Gtricks Forum in 2.2 :) ✭✭✭

    I think its possible. Look the code in views folder and copy the same.

    Vanilla is sweet & support is great, to encourage volunteers, please donate.

  • KasperKasper Scholar of the Bits Copenhagen Vanilla Staff

    I did this in the first version of VanillaBootstrap, you can find the code here: https://github.com/kasperisager/VanillaBootstrap/blob/v0.9a-2.0/views/default.master.tpl#L80

    It should be pretty straight forward as it's just a simple HTML form.

    Kasper Kronborg Isager (kasperisager) | Front-end Developer @Vanilla | Hit me up: Google Mail or Vanilla Mail | Find me on GitHub

  • edited May 2012

    Thanks @kasperisager for the replies i think @aery is on the right track I have had a look in \application\dashboard\view\entry files and tried copying various code but not having any luck as am not sure what file to copy from. Hoping @Todd or someone can answer this

  • peregrineperegrine ☯ hasta luego :) In-Flight MVP

    Just an idea. You'll probably have more help, if you post your code and where you are having problems and a link to your site showing the problem. Otherwise, it seems like you want someone to write it for you from scratch (which may or may not happen). Often times, there are more responses when you show that you have been putting energy into it and provide your work thus far.

    Monetary Donations will be appreciated if you use my plugins. Thanks in Advance.
    As a waiter gets a tip for a good meal, tips for successful solutions appreciated as well. Peregrine

  • Thanks peregrine. Basically I have a blank page (custompages plugin) Im wanting to have the things that appear in the sign-in popup on this page. I can get the html code by viewing source of signin popup and just coping that to the page and it seems to work. But i was hoping there is some php i could use (eg from one of the pages in \application\dashboard\view\entry) that would be much cleaner probably better?

  • hbf said: Just use the php code from the form...

    Im guessing you mean the php code from the \application\dashboard\view\entry\signin.php page in vannila? If so yeah I tried this but am getting a bonk error also tried the index.php with the same result

  • hbfhbf wiki guy? MVP

    Sorry im not able to get to a dev box, but if you post the code that you pit in the page and the details of the bonk ill try to help debug. Its likely missing some innocuos object reference or something.

  • edited May 2012

    thanks alot cause my php is skills are fairly limited.

    signin.php

    <?php if (!defined('APPLICATION')) exit();
    $Methods = $this->Data('Methods', array());
    $SelectedMethod = $this->Data('SelectedMethod', array());
    $CssClass = count($Methods) > 0 ? ' MultipleEntryMethods' : ' SingleEntryMethod';
    
    // Testing
    //$Methods['Facebook'] = array('Label' => 'Facebook', 'Url' => '#', 'ViewLocation' => 'signin');
    //$Methods['Twitter'] = array('Label' => 'Twitter', 'Url' => '#', 'ViewLocation' => 'signin');
    
    echo '<div class="Entry'.$CssClass.'">';
       echo '<h1>'.$this->Data('Title').'</h1>';
    
       // Render the main signin form.
       echo '<div class="MainForm">';
    
       include $this->FetchViewLocation('passwordform');
    
       echo $this->Data('MainForm');
    
       echo '</div>';
    
       // Render the buttons to select other methods of signing in.
       if (count($Methods) > 0) {
          echo '<div class="Methods">'
             .Wrap('<b>'.T('Or you can...').'</b>', 'div');
    
          foreach ($Methods as $Key => $Method) {
             $CssClass = 'Method Method_'.$Key;
             echo '<div class="'.$CssClass.'">',
                $Method['SignInHtml'],
                '</div>';
          }
    
          echo '</div>';
       }
    
    echo '</div>';
    
  • edited May 2012

    and index.php

    <?php if (!defined('APPLICATION')) exit(); ?>
    <div id="SignIn" class="AjaxForm">
       <?php include($this->FetchViewLocation('SignIn')); ?>
    </div>
    <div id="Password" class="AjaxForm">
       <?php include($this->FetchViewLocation('PasswordRequest')); ?>
    </div>
    <div id="Register" class="AjaxForm">
       <?php include($this->FetchViewLocation($this->_RegistrationView())); ?>
    </div>
    
  • edited May 2012

    Thanks (sorry I didnt know about debugging) error from index.php

    Could not find a 'signin' view for the 'plugin' controller in the 'dashboard' application. The error occurred on or near: /home/mmatippi/domains/mma-tipping.com/public_html/fs/library/core/class.controller.php (line 780 was highlighted)

    776:          $this->_ViewLocations[$LocationName] = $ViewPath;
    777:       }
    778:       // echo '<div>['.$LocationName.'] RETURNS ['.$ViewPath.']</div>';
    779:       if ($ViewPath === FALSE && $ThrowError)
    780:          trigger_error(ErrorMessage("Could not find a '$View' view for the '$ControllerName' controller in the '$ApplicationFolder' application.", $this->ClassName, 'FetchViewLocation'), E_USER_ERROR);
    781: 
    782:       return $ViewPath;
    783:    }
    784: 
    
  • Error message for signin.php: Could not find a 'passwordform' view for the 'plugin' controller in the 'dashboard' application. With same code as above

  • peregrineperegrine ☯ hasta luego :) In-Flight MVP
    edited May 2012

    uncomment line 778 and see what that displays.

    add

    var_dump($ViewPaths);

    before lines starting with 1 2 3 and 4 - lines 748 thru lines 761

    Monetary Donations will be appreciated if you use my plugins. Thanks in Advance.
    As a waiter gets a tip for a good meal, tips for successful solutions appreciated as well. Peregrine

  • sorry I just realised I left the message at the top of page off. It was:

    Fatal Error in PluginController.FetchViewLocation(); then error I posted above

    Thanks peregrine I will try this when I get home

  • hbfhbf wiki guy? MVP

    the code

    php include($this->FetchViewLocation('SignIn'));

    is trying to find a view called signin that is related to the controller that called the view you are in (plugin controller)

    while there may be other solutions... i would suggest either copying the view file Signin to the views directory of the custom pages plugin, or removing the include and absorbing the code from that view into the page you are creating.

    an alternate would be to invoke the view by referencing it via the proper controller, but i don't have a quick answer on how to do that.

  • include($this->FetchViewLocation('SignIn', 'entry', 'dashboard'));

    grep is your friend.

  • edited May 2012

    thanks x00 for the help but I get the same error putting that code in. hbf I tried copying the Signin view file over but didnt have any luck.

  • hbfhbf wiki guy? MVP

    x00 said: include($this->FetchViewLocation('SignIn', 'entry', 'dashboard'));

    Thanks, we need to document th interface and all of the overloads for these useful core functions on the wiki...

    adz0007 said: thanks x00 for the help but I get the same error putting that code in. hbf I tried copying the Signin view file over but didnt have any luck.

    Im a bit perplexed that adding the controller and application path to the view fetch didnt work. I would bet the error was similar but not the exact same... probably a different object we need to get a proper handle on. Maybe try it again and copy paste the precise error in here again..

  • here you go, sorry I'm probably something simple wrong, its a bit complex for me

    Fatal Error in PluginController.FetchViewLocation();

    Could not find a 'passwordform' view for the 'plugin' controller in the 'dashboard' application. The error occurred on or near: /home/mmatippi/domains/mma-tipping.com/public_html/fs/library/core/class.controller.php

    776:          $this->_ViewLocations[$LocationName] = $ViewPath;
    777:       }
    778:       // echo '<div>['.$LocationName.'] RETURNS ['.$ViewPath.']</div>';
    779:       if ($ViewPath === FALSE && $ThrowError)
    780:          trigger_error(ErrorMessage("Could not find a '$View' view for the '$ControllerName' controller in the '$ApplicationFolder' application.", $this->ClassName, 'FetchViewLocation'), E_USER_ERROR);
    781: 
    782:       return $ViewPath;
    783:    }
    784: 
    

    Backtrace:

    /home/mmatippi/domains/mma-tipping.com/public_html/fs/library/core/class.controller.phpPHP::Gdn_ErrorHandler();
    [/home/mmatippi/domains/mma-tipping.com/public_html/fs/library/core/class.controller.php:780] PHP::trigger_error();
    [/home/mmatippi/domains/mma-tipping.com/public_html/fs/applications/dashboard/views/entry/signin.php:16] Gdn_Controller->FetchViewLocation();
    [/home/mmatippi/domains/mma-tipping.com/public_html/fs/plugins/CustomPages/pages/index.php:9] PHP::include();
    [/home/mmatippi/domains/mma-tipping.com/public_html/fs/library/core/class.controller.php:659] PHP::include();
    [/home/mmatippi/domains/mma-tipping.com/public_html/fs/library/core/class.controller.php:1073] Gdn_Controller->FetchView();
    [/home/mmatippi/domains/mma-tipping.com/public_html/fs/library/core/class.pluggable.php:195] Gdn_Controller->xRender();
    [/home/mmatippi/domains/mma-tipping.com/public_html/fs/plugins/CustomPages/default.php:41] Gdn_Pluggable->__call();
    [/home/mmatippi/domains/mma-tipping.com/public_html/fs/plugins/CustomPages/default.php:41] PluginController->Render();
    [/home/mmatippi/domains/mma-tipping.com/public_html/fs/library/core/class.pluginmanager.php:713] CustomPagesPlugin->PluginController_Page_Create();
    [/home/mmatippi/domains/mma-tipping.com/public_html/fs/library/core/class.dispatcher.php:313] Gdn_PluginManager->CallNewMethod();
    [/home/mmatippi/domains/mma-tipping.com/public_html/fs/index.php:53] Gdn_Dispatcher->Dispatch();
    

    Variables in local scope:

    [View] 'passwordform'
    [ControllerName] 'plugin'
    [ApplicationFolder] 'dashboard'
    [ThrowError] true
    [LocationName] 'dashboard/plugin/passwordform'
    [ViewPath] false
    [BasePath] '/home/mmatippi/domains/mma-tipping.com/public_html/fs/applications'
    [SubPaths] array (
      0 => 'views/plugin/passwordform',
    )
    [ViewPaths] array (
      0 => '/home/mmatippi/domains/mma-tipping.com/public_html/fs/themes/Fantasy Surf Team/dashboard/views/plugin/passwordform.*',
      1 => '/home/mmatippi/domains/mma-tipping.com/public_html/fs/themes/Fantasy Surf Team/views/plugin/passwordform.*',
      2 => '/home/mmatippi/domains/mma-tipping.com/public_html/fs/applications/dashboard/views/plugin/passwordform.*',
    )
    [SubPath] 'views/plugin/passwordform'
    [Glob] '/home/mmatippi/domains/mma-tipping.com/public_html/fs/applications/dashboard/views/plugin/passwordform.*'
    [Paths] array (
    )
    
  • peregrineperegrine ☯ hasta luego :) In-Flight MVP
    edited May 2012

    the viewpaths seem to be picking up 3 directories. from the fetchview in signin.php for

    line 16: include $this->FetchViewLocation('passwordform');

    did you try creating this directory

    It's looking for themes/Fantasy Surf Team/views/plugin/

    and putting /applications/dashboard/views/entry/passwordform.php into

    themes/Fantasy Surf Team/views/plugin/passwordform.php

    it seems to assume plugin folder if not an application

    Frankly this all mystifies me, so I am just guessing

    Monetary Donations will be appreciated if you use my plugins. Thanks in Advance.
    As a waiter gets a tip for a good meal, tips for successful solutions appreciated as well. Peregrine

  • edited May 2012

    hmm am getting this error now

    Fatal error: Call to a member function Open() on a non-object in /home/mmatippi/domains/mma-tipping.com/public_html/fs/themes/Fantasy Surf Team/views/plugin/passwordform.php on line 6

    guessing I need to change the Url on line 6? Ive tried a few different things but dont fully understand it so im basically guessing

    <?php if (!defined('APPLICATION')) exit(); ?>
    <div>
       <?php
       // Make sure to force this form to post to the correct place in case the view is
       // rendered within another view (ie. /dashboard/entry/index/):
       echo $this->Form->Open(array('Action' => $this->Data('FormUrl', Url('/entry/signin')), 'id' => 'Form_User_SignIn'));
       echo $this->Form->Errors();
       ?>
       <ul>
          <li>
             <?php
                echo $this->Form->Label('Email/Username', 'Email');
                echo $this->Form->TextBox('Email');
             ?>
          </li>
          <li>
    
  • edited May 2012

    Am interrested in this.

    FYI I did the... include($this->FetchViewLocation('SignIn', 'entry', 'dashboard'));

    ...in default.master.php

    Worked fine if the page was at the sigin URL, .../entry/register

    However at the home page URL it bonked.

  • x00x00 MVP
    edited May 2012

    You are going to have to construct these forms yourself as modules, you can't really take something out of context and expect it work as if it was in context. it is not just a case of copying files across.

    Be happy with a simple logon form using standard markup if you are a php novice. Of course it won't have the connects, but if you aren't using them I wouldn't worry.

    You could also fetch the asset with jquery an insert it in a div, which is very similar to the current popup except it could be automatic. Like so:

    Add to your theme's /js/custom.js

    jQuery(document).ready(function($){
          $('#SignInForm').load('/entry/signin?DeliveryType=VIEW&DeliveryMethod=XHTML&Target='+encodeURIComponent(location.pathname));
    });
    

    and create a div somewhere on your page with the id SignInForm

    It is not really efficient though. I would do it so you click on somethign and it appears, but in you case it will appears in place rather than floating popup.

    That is all the help I have time to give.

    grep is your friend.

    adz0007
  • edited May 2012

    I have also tried coding it into the default.naster.php page like so....

    <?php if (!$Session->IsValid()) { ?> <form id="Form_User_SignIn" method="post" action="/community/forum/entry/signin"> <input type="hidden" id="Form_hpt1" name="User/hpt" value="" style="display: none;" /> <input type="hidden" id="Form_ClientHour1" name="User/ClientHour" value="<?php echo date('Y-m-d H:i'); ?>" /> <input type="hidden" id="Form_TransientKey1" name="User/TransientKey" value="<?php echo Gdn::Session()->TransientKey(); ?>" /> <input type="hidden" id="Form_Target1" name="User/Target" value="/" /> <ul> <label for="Form_Email">Email/Username</label> <input type="text" id="Form_Email1" name="User/Email" value="" class="InputBox" /> <label for="Form_Password">Password</label> <input type="password" id="Form_Password1" name="User/Password" value="" class="InputBox Password" /> <input type="submit" id="Form_SignIn" name="User/Sign_In" value="Sign In" class="Button" /> <label for="SignInRememberMe" class="CheckBoxLabel"> <input type="checkbox" id="SignInRememberMe" name="User/RememberMe" value="1" /> <input type="hidden" name="Checkboxes[]" value="RememberMe" /> Keep me signed in</label> <a href="/community/forum/entry/passwordrequest" class="ForgotPassword">Forgot?</a> </form> <?php } ?>

    `

    However It doesn't work. Am assuming there is a transientkey value problem.

    On the upside I can get it exactly where I want it on the page, so not a total fail :-).

  • Thank you for the above.

    Have implemented it and it pretty well all works a treat.

    Just one strange thing going on with the "forgot?" link. When I hover the mouse over the link it shows the target URL (.../forum/entry/passwordrequest) in the browser status, however when it is clicked it stays on the same page and the username/password boxes disappear.

    No obvious errors are reported by the browser (firefox 8.0.1)

  • x00x00 MVP
    edited May 2012

    try change the line to

    echo Anchor(T('Forgot?'), '/entry/passwordrequest');

    that should hopefully stop any js shenanigans.

    grep is your friend.

    slaretibartfast
  • Thanks all especially x00 that works great thanks.

  • x00 said: try change the line to

    echo Anchor(T('Forgot?'), '/entry/passwordrequest');

    that should hopefully stop any js shenanigans.

    Smooth! Nice one.

Sign In or Register to comment.