psy Posted November 2, 2019 Share Posted November 2, 2019 I want to have both a login form and a registration form on the same page. After much tweaking in CSS & Hooks, I managed to get @ryan's LoginRegister module to display as required. All goes well until it doesn't, ie if there is an error in the form submission. Each form has the wrapper ID hardcoded to "LoginRegister". Problem is when both forms are on the same page, both forms get the error messages and the Login form turns into a Register form. See attached before-and-after images and my code is in the 'spoiler'. Spoiler <?php namespace ProcessWire; // the message doesnt work but the goose user who tried to login with both client and admin roles is auto-logged out $message = ''; if ($input->get('logout')==1 && $input->get('g')==1 ) { $message = "You have been auto-logged out as the account you logged in with has both Client and Admin privileges which would completely screw up the application!"; } if($user->isLoggedin() && !$input->get('profile') && !$input->get('logout')) { // you take over and render your own output or redirect elsewhere $session->redirect('/dashboard/'); } else { $wire->addHookBefore('Inputfield::render', function ($event) { $inputfield = $event->object; if ($inputfield instanceof InputfieldTextarea) { // textarea input $inputfield->addClass('form-control'); $inputfield->columnWidth = 100; } else if ($inputfield instanceof InputfieldText) { // includes most single-line text types $inputfield->addClass('form-control'); $inputfield->columnWidth = 100; } else if ($inputfield instanceof InputfieldSubmit) { // submit button $inputfield->addClass('button button-rounded'); } if ($inputfield->required) { $inputfield->addClass('required'); $inputfield->attr('required','required'); } }); $loginRegister = $modules->get('LoginRegister'); $loginRegister->set('renderStyles', false); $loginRegister->set('renderScripts', true); if ($input->get('register')|| $input->get('register_confirm')) { $loginRegister->set('features', array('login', 'register', 'profile', 'forgot','login-email')); } else { $loginRegister->set('features', array('login', 'profile', 'forgot','login-email')); } $loginForm = $loginRegister->execute(); $loginRegister->set('features', array('login', 'register', 'profile', 'forgot','login-email')); $input->get->register = 1; $registerForm = $loginRegister->execute(); $input->get->register = 0; } ?> <region id="regHeadCSS"> <link type="text/css" href="/wire/templates-admin/styles/font-awesome/css/font-awesome.min.css?v=30e" rel="stylesheet"> <?php foreach(wire('config')->styles as $file) : ?> <link rel='stylesheet' type='text/css' href='<?=$file?>' /> <?php endforeach;?> </region> <region id="regContent"> <!-- Content ============================================= --> <section id="content"> <div class="content-wrap"> <div class="container clearfix"> <div class="col_one_third nobottommargin"> <div class="well well-lg nobottommargin"> <?=$message?> <?php if (!$input->get('register') && !$input->get('register_confirm')) : ?> <?php try { echo $loginForm; } catch (WireException $e) { echo "Too many failed login attempts.<br>" . $e->getMessage(); } ?> <?php endif;?> </div> </div> <div class="col_two_third col_last nobottommargin"> <?=$page->body?> <?php // needed to avoid server 500 error when user tries to login too many times in the other form try { echo $registerForm; } catch (WireException $e) { echo "Too many failed login attempts.<br>" . $e->getMessage(); } ?> </div> </div> </div> </section><!-- #content end --> </region><!--regContent--> Help to fix much appreciated Link to comment Share on other sites More sharing options...
dragan Posted November 2, 2019 Share Posted November 2, 2019 This is a very hackish solution, but then again it's Saturday, I have never used the LR module before, and I could do with more coffee :) Spoiler if($page->id === 1027) { if( !isset($_GET["register"]) && !isset($_GET["login"]) ) { $content .= $modules->get('LoginRegister')->execute(); $css = "<style> .LoginRegisterLinks { display: none; } #ireg { display: block; border: none; height: 100vh; width: 100%; overflow: hidden; } </style>"; $thisUrl = $pages->get(1027)->url; $iframe = "<iframe id='ireg' src='$thisUrl?register=1'></iframe>"; $content .= $css . $iframe; } else { $css = "<style> .LoginRegisterLinks { display: none; } h1, .languages, .topnav, .breadcrumbs, .search, footer { display: none !important; } body { padding: 0; } </style>"; $content .= $css; $content .= $modules->get('LoginRegister')->execute(); } } Basically: Create an iFrame. May not be elegant, but it seems to work. You'd have to add a logic for the registration confirmation page, so that this doesn't load in the iframe, but in its own page. btw, the very first line above was me trying out another idea: create several pages with the LR-template and then tinker around with form targets or hidden input fields. 1 Link to comment Share on other sites More sharing options...
psy Posted November 2, 2019 Author Share Posted November 2, 2019 Thanks @dragan will give it a try. Another idea I had was to use FormBuilder for the login form - again hackish. Really wish PW had a solid Login/Register module... 2 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now