Forums

Need some login form help (7 posts)

  1. mach2racer
    Member
    Posted 3 years ago #

    I have a site that is wanting a login for users. But the problem is how do you redirect them to the front page? When they login they go to the dashboard. anyone?
    Here is the code..

    <form class="ddfm" name='loginform' id='loginform' action='/wp-login.php' method='post'>
    
    		<p class="fieldwrap"><label for="log">Username</label><input class="fmtext" type="text" name="log" id="log" value="" tabindex='1' /></p>
    		<p class="fieldwrap"><label for="pwd">Password</label><input class="fmtext" type='password' name='pwd' id='pwd' value='' tabindex='2' /></p>
    		<input name='rememberme' type='hidden' id='rememberme' value='false' />
    		<div class="submit">
    			<input type='submit' name='submit' id='submit' value='Login &raquo;' tabindex='3' />
    			<?php //use a hidden field to return them to the page they came from ?>
    			<input type="hidden" name="redirect_to" value="<?php echo $_SERVER["REQUEST_URI"]; ?>
    		</div>
    	  </form>
  2. Vaughan van Dyk
    Member
    Posted 3 years ago #

    Hi,

    You need to specify your home page in the redirect_to parameter. In otherwords, change the following line of code from

    <input type="hidden" name="redirect_to" value="<?php echo $_SERVER["REQUEST_URI"]; ?>

    to

    <input type="hidden" name="redirect_to" value="<?php echo get_option('home'); ?>" />

    There were a couple syntax errors in your original code. When corrected, your original redirect parameter should return the user to the page from which they logged in (which is usually the preferred behaviour). To do that, the last input line should have been as follows:

    <input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>"/>

    Also, if your login form is not working correctly, you should change the action parameter in the first line from

    action='/wp-login.php'

    to

    action='<?php bloginfo('url') ?>/wp-login.php'

    Hope that helps.
    Vaughan

  3. mach2racer
    Member
    Posted 3 years ago #

    That Might help. Thanks alot

  4. mach2racer
    Member
    Posted 3 years ago #

    I just tried still takes it to the dashboard.. I thought that it would work,

  5. Vaughan van Dyk
    Member
    Posted 3 years ago #

    Hi,

    I tried the code in a few themes and it works by returning users to the site's home page. Just to confirm the full code for you:

    <form class="ddfm" name='loginform' id='loginform' action='<?php bloginfo('url') ?>/wp-login.php' method='post'>
    <p class="fieldwrap"><label for="log">Username</label><input class="fmtext" type="text" name="log" id="log" value="" tabindex='1' /></p>
    <p class="fieldwrap"><label for="pwd">Password</label><input class="fmtext" type='password' name='pwd' id='pwd' value='' tabindex='2' /></p>
    <input name='rememberme' type='hidden' id='rememberme' value='false' />
    <div class="submit">
    <input type='submit' name='submit' id='submit' value='Login &raquo;' tabindex='3' />
    <?php //use a hidden field to return them to the page they came from ?>
    <input type="hidden" name="redirect_to" value="<?php echo get_option('home'); ?>" />
    </div>
    </form>

    Also, when you say it redirects you to the Dashboard do you mean within the actual WordPress Admin panel or just to the main WordPress login screen? What happens when you log in with an incorrect username or password? I'd try it in another theme just to check and also double-check you have cookies enabled.

    Good luck.
    Vaughan

  6. mach2racer
    Member
    Posted 3 years ago #

    Okay I took the code you put up.. It got me an error 404. It was on the site though? But I did not login though..

  7. mach2racer
    Member
    Posted 3 years ago #

    Oh and I have the cookies enabled

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags