0

My developer built our registration page to display a div when logins failed based on a string in the URL.

When logins fail this is added to the URL /login?msg=invalid

The PHP in my login.phtml which displays the error messages based on the msg= parameter is

<?php 
$msg = "";
$msg = $_GET['msg'];
if($msg==""){ $showMsg = ""; }
elseif($msg=="invalid"){ $showMsg = '            <div class="alert alert-error">
        <a class="close" data-dismiss="alert">×</a>
        <strong>Error!</strong> Login or password is incorrect!
    </div>'; }
elseif($msg=="disabled"){ $showMsg = "Your account has been disabled."; }
elseif($msg==2){ $showMsg = "Your account is not activated. Please check your email."; }
?>

In the controller the redirect to that URL is

        else //email id does not exist in our database
        {
            //redirecting back with invalid email(invalid) msg=invalid.
            $this->_redirect($url."?msg=invalid");
        }

I know there are a few other validation types for disabled accounts etc. I'm in the process of redesigning the entire interface and would like to get rid of this kind of validation so that the div tags display when logins fail but not show the URL strings.

If it matters the new div I want to display is

<div class="alert alert-error alert-login">
    Email or password incorrect
</div>

I'd like to replace the php my self in my login.phtml and controller but not a good programmer. What can I replace $this->_redirect($url."?msg=invalid"); with so that no strings are added to the URL and display the appropriate div tags?

Thanks

2 Answers 2

0

Passing a msg through a GET parameter is a bit weird to me.

See this thread discussing other ways to send a message to the page, using sessions, cookies or database, here.

I'm not familiar with the zend framework, but there has to be a way to set a "flash" message through the session.

0

change this in loginAction of your contorller

$this->_redirect($url."?msg=invalid");

to

$this->view->message = $msg;

then add to your code to login.phtml

<?php if ($this->message) :?>
  <div class="alert alert-error alert-login">
  Email or password incorrect
  </div>
<? endif; ?>
... your form code there
2
  • This gives me an error Fatal error: Uncaught exception 'Zend_View_Exception' with message 'script 'user/login.phtml' not found in path (application/default/views/scripts/)' in /usr/share/php/Zend/View/Abstract.php:976 Stack trace: #0 /usr/share/php/Zend/View/Abstract.php(876): Zend_View_Abstract->_script('user/login.phtm...') #1 /usr/share/php/Zend/Controller/Action/Helper/ViewRenderer.php(897): Zend_View_Abstract->render('user/login.phtm...') #2 It's longer....
    – Anagio
    Dec 9, 2012 at 22:02
  • do you have application/default/views/scripts/user/login.phtml ?
    – pliashkou
    Dec 16, 2012 at 21:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.