XF 2.1 Registration redirect

Ozzy47

Well-known member
When a user successfully registers on the site they are redirected to index.php?register/complete, and they are show a block saying:

Thanks for registering. Your registration is now complete.

Now in my register file, I try to mimic this when someone fails the registration. I have the following:

PHP:
            // Show bot false success message
            $viewParams = [
                      'redirect' =>($this->buildLink('index'))
                ];
                return $this->view('XF:Register\Complete', 'register_complete',
$viewParams);
Pretty sure this is the code XF uses for successful registrations.

Problem is the user is not redirected, they stay on whatever page they were viewing and only get shown the block. I really would like to get the redirect working the same as a successful registration.
 
You're looking at the controller action that corresponds to the success message. The redirect view parameter there is for something else. Visitors are redirected to that page from other actions via a redirect reply ($this->redirect($this->buildLink('register/complete'));).
 
You're looking at the controller action that corresponds to the success message. The redirect view parameter there is for something else. Visitors are redirected to that page from other actions via a redirect reply ($this->redirect($this->buildLink('register/complete'));).

Thanks for replying.

Using that code $this->redirect($this->buildLink('register/complete')); , gives this error, The requested page could not be found. (Code: no_reply, controller: XF:Register, action: Register)
 
@ozzy47, in your first post above you were calling the registration complete template and so it simply opened in an overlay.
You are probably looking to create a function similar to actionComplete(), say call it actionReject(), that returns that template. Or better yet, your own template as the registration complete one mostly relies on being viewed by a user (the newly created one).
Then when you reject a registration, send the viewer to that function which will take them away from the page they were viewing - which I think is what you are after.
return $this->redirect($this->buildLink('register/reject'));
 
Quick question. If the user is not a bot, I return them to the XF action register function, return parent::actionRegister(); so once I write my function for the bot, would the return look like this, return parent::actionReject(); ? That don’t seem quite right as the function would be in my file, not the parent file.
 
I'm still not quite sure where you are going with this add-on. In which function are you running your checks and then rejecting the registration? Are you extending and checking inside actionRegister()? If so, are you doing this before any of the default code?
 
In my register.php file I extend the actionRegister function and do some checks. If they pass the checks, I then return them to the parent register.php file and let XF handle the registration process. If they fail the checks, I don’t send them back. I show them the successful message. But I would also like to redirect them to the register/complete page as to not set off any flags.
 
To use register/complete you'll have to extend it in order to skip the user_id check otherwise it will fail since the registartion never took place.
You can either pass in a variable indicating you wish to skip the check or you can create your own function as discussed earlier with either the same template or a new one. Instead of 'reject' you can call it 'complete2' or similar to make the link look other than a rejection.
Maybe something like this for a new function, otherwise build the link with a parameter so you can skip the user_id check in actionComplete():
PHP:
public function actionRegister()
{
    $this->assertPostOnly();
    $this->assertRegistrationActive();
    
    if (true) // placeholder for your checks
    {
        return $this->redirect($this->buildLink('register/complete2')); // complete2 is your new function that skips the user_id check
    }
    
    return parent::actionRegister();
}
 
Top Bottom