Redirect User To New Page From Registration Page

Discussion in 'Joomla' started by heshan86, Jan 29, 2010.

  1. #1
    Hi,

    Im trying to redirect a user to a new page when they get an error in the registration page (like when they type a username or email address that is already in use in the signup form). Already in my site when a user registers they get redirected to a new page. I did this by editing the controller.php file. Im wondering how to redirect a user to a new page when they get an error in the registraion page ? it has to be from the controller.php file i guess. But not sure where to edit ?

    thanks
     
    heshan86, Jan 29, 2010 IP
  2. heshan86

    heshan86 Active Member

    Messages:
    89
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #2
    well i know that i have to edit the registration function to redirect the user to a different page if there is an error during registration like typing a username or an email already in use. Heres the function im trying edit, but still im not sure what exactly i should edit

    function register_save()
    {
    global $mainframe;

    // Check for request forgeries
    JRequest::checkToken() or jexit( 'Invalid Token' );

    // Get required system objects
    $user = clone(JFactory::getUser());
    $pathway =& $mainframe->getPathway();
    $config =& JFactory::getConfig();
    $authorize =& JFactory::getACL();
    $document =& JFactory::getDocument();

    // If user registration is not allowed, show 403 not authorized.
    $usersConfig = &JComponentHelper::getParams( 'com_users' );
    if ($usersConfig->get('allowUserRegistration') == '0') {
    JError::raiseError( 403, JText::_( 'Access Forbidden' ));
    return;
    }

    // Initialize new usertype setting
    $newUsertype = $usersConfig->get( 'new_usertype' );
    if (!$newUsertype) {
    $newUsertype = 'Registered';
    }

    // Bind the post array to the user object
    if (!$user->bind( JRequest::get('post'), 'usertype' )) {
    JError::raiseError( 500, $user->getError());
    }

    // Set some initial user values
    $user->set('id', 0);
    $user->set('usertype', '');
    $user->set('gid', $authorize->get_group_id( '', $newUsertype, 'ARO' ));

    $date =& JFactory::getDate();
    $user->set('registerDate', $date->toMySQL());

    // If user activation is turned on, we need to set the activation information
    $useractivation = $usersConfig->get( 'useractivation' );
    if ($useractivation == '1')
    {
    jimport('joomla.user.helper');
    $user->set('activation', JUtility::getHash( JUserHelper::genRandomPassword()) );
    $user->set('block', '1');
    }

    // If there was an error with registration, set the message and display form
    if ( !$user->save() )
    {
    JError::raiseWarning('', JText::_( $user->getError()));
    $this->register();
    return false;
    }

    // Send registration confirmation mail
    $password = JRequest::getString('password', '', 'post', JREQUEST_ALLOWRAW);
    $password = preg_replace('/[\x00-\x1F\x7F]/', '', $password); //Disallow control chars in the email
    UserController::_sendMail($user, $password);

    // Everything went fine, set relevant message depending upon user activation state and display message
    if ( $useractivation == 1 ) {
    $message = JText::_( 'REG_COMPLETE_ACTIVATE' );
    } else {
    $message = JText::_( 'REG_COMPLETE' );
    }

    $this->setRedirect('index.php', $message);
    }
     
    heshan86, Jan 29, 2010 IP