Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6916671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:37:58+00:00 2026-05-27T09:37:58+00:00

I have a view with a username, password and a submit button. This view

  • 0

I have a view with a username, password and a submit button. This view is called login.ctp, so the way I had it previous to CakePHP was I had a <div> at the top of the page and in that <div> the login would be visible through out all the pages so basically you can log in from anywhere, I was using AJAX. My issue now is that I do not know how to do it in CakePHP because some of the other views have a <form> tag, and I think it needs a <form> tag for the login too? so they conflict..Also, so two things

  1. How can I place that div back at the top of the page and make it work with my login function in the UsersController ?

  2. How can I do it so that the <forms> do not conflict?

related code

<?php
class UsersController extends AppController {

    var $uses = array("User");
    var $components = array('Auth', 'Session');


    function index()
    {
        $this->set('users', $this->User->find('all'));
         $this->layout = 'master_layout';
    }

    function beforeFilter() {
       $this->Auth->allow('add');
      } 

      function add() { 

          if (!empty($this->data)) {
             //pass is hashed already
             //->data['User']['password'] = $this->Auth->password($this->data['User']['password']);
             if ($this->User->save($this->data)) {
                $this->Session->setFlash('Your were registered!.');
                               $this->redirect(array('action' => 'index'));
             }
          }

         $this->layout = 'master_layout';
      }

    //IF THE DATABASE IS SET UP CORRECTLY CAKE AUTHENTICATES AUTOMATICALLY NO
    //LOGIC IS NEEDED FOR LOGIN http://book.cakephp.org/view/1250/Authentication
    function login() {
        $this->layout = 'master_layout';
        $this->data['User']['password'] = '';

    }

    function logout() {

    $this->redirect($this->Auth->logout());

    }

}
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:37:59+00:00Added an answer on May 27, 2026 at 9:37 am

    This is pretty simple. If you want to form to repeat across more than just one page, you should use an element. Create the loginform.ctp file in the app/views/elements folder and just put a <?php echo $this->element('loginform'); ?> wherever you want it. In your loginform.ctp file, you should have something like this:

    <div id="loginform">
    <?php echo $form->create('User', array('controller' => 'Users','action' => 'login')); ?>
    <?php echo $form->input('email', array('label' => 'Email'))    ?>
    <?php echo $form->input('password',array('type'=>'password', 'label' => 'password')) ?>
    <?php echo $form->submit('Submit'); ?>
    </div>
    

    As long as you specify which controller and action the form is for, Cake will take care of it so that the forms do not conflict.

    If that doesn’t work, try just the html:

    <form id="UserLoginForm" method="post" action="/users/login" accept-charset="utf-8"><div style="display:none;"><input type="hidden" name="_method" value="POST" /></div><ul>
    <li><div class="input text required"><label for="UserEmail">Email</label><input name="data[User][email]" type="text" class="field text large" maxlength="255" value="" id="UserEmail" /></div></li>
    <li><div class="input password"><label for="UserPassword">password</label><input type="password" name="data[User][password]" class="field text large" value="" id="UserPassword" /></div></li>
    <li><div class="submit"><input type="submit" value="Submit" /></div></li>
    </ul>
    </form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Partial view (Login, with username, password and Submit button), and the
i have a partial view with a login form (with username and password fields)
I have the following code for my login view: <?php echo $session->flash('auth'); echo $this->Form->create('User',
I have a view user control that can post form. This control can be
We have a View (call it X) that is the base view called by
I have a form in my view page on submit a function in a
I have a login function in my controller that was getting called before, but
So I have Authlogic working fine with this user_sessions/new view: <% form_for @user_session, :url
how to create a widget out of an existing login action view ? this
I have a user controller that checks to login a user. It has this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.