0

I have this method

public function createParticipantAction(){
  ...
  $checkData = $this->validateData($data);
  if($checkData==true){
     $this->_redirect('course/participant/create');
     exit();
  }
  ...
}

public function validateData($data){
if($data){
    $session = Mage::getSingleton('core/session');
    $validateData = Mage::getModel('course/participant');
    $validateData->addData($data);
    $name = $validateData->getName();
    if($name==''){
        $session->addError('Name Error');
    }
    return true;
 }
  return false;

}

When calling $this->validateData($data), if the name is null, it will exit and redirect to the registration page. But right now it doesn't work.

Help me, please!

1

try this

$checkData = $this->validateData($data);
  if($checkData==false){
     $this->_redirect('course/participant/create');
     return;
  }

&

public function validateData($data){

    $session = Mage::getSingleton('core/session');
    $validateData = Mage::getModel('course/participant');
    if($data['name']==''){
        $session->addError('Name Error');
        return false;
    }
 }
| improve this answer | |
0

exit() will stop execution so the redirect part will not work.

Please try to use exit() after the redirect, like this:

public function validateData($data){

    $session = Mage::getSingleton('core/session');
    $validateData = Mage::getModel('course/participant');
    $validateData->addData($data);
    $name = $validateData->getName();
    if($name==''){
        $session->addError('Name Error');
        $this->_redirect('course/participant/create');
        exit();
    }
 }
| improve this answer | |
  • Hi Toan Tam. Can i chat with you in skype? – Hưng Nguyễn May 13 at 6:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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