XF 2.2 Page works regularly but not in modal from data-xf-click="overlay"

kmecpp

Member
Trying to make a custom registration form but its not working in a modal (A modal does pop up but it says "Oops! We ran into some problems. Please try again later. More error details may be in the browser console.")

The error displayed in the browser's console is just "PHP: (Followed by the full HTML of the desired page (modal html + surrounding page html)"

The page works fine when just visiting it in the URL (going to website.com/registration) but not as a modal.

The button that opens the modal:
Code:
<a href="{{ link('registration') }}" class="guest-link p-navgroup-link p-navgroup-link--textual p-navgroup-link--register" rel="nofollow" data-xf-click="overlay">
    <span class="p-navgroup-linkText">Sign Up</span>
</a>


My controller:

Code:
class Registration extends AbstractController {

    protected function preDispatchController($action, ParameterBag $params) {
        \XF\Pub\App::$allowPageCache = false;
    }

    public function actionIndex() {
        XF::logError("It ran");
        return $this->view(false, 'registration', []);
    }

}

I get the "It ran" error message when the button is clicked on and the modal pops up so I know its running.

What am I doing wrong here?
 

Lukas W.

Well-known member
Without debugging it, my first hunch would be your missing view class. You don't need to actually create one, but declaring it as false might have some side effects.

If you're intending to replace the default XF registration, I'd instead recommend to replace the template with your markup and the submit function with your custom code as needed instead, otherwise you'll end up with two different ones.
 

kmecpp

Member
Without debugging it, my first hunch would be your missing view class. You don't need to actually create one, but declaring it as false might have some side effects.

If you're intending to replace the default XF registration, I'd instead recommend to replace the template with your markup and the submit function with your custom code as needed instead, otherwise you'll end up with two different ones.
Using an empty string or random string or mimicing what the default registration controller does (XF:Register\Form) doesn't work either. Its the same problem.

I just want to totally disable the default registration and replace it with some static HTML. If I disable user registration in the admin panel the template isn't rendered at all though.
 

kmecpp

Member
@Lukas W. Inspecting the network data received when clicking on the buttons I found that when it's functioning correctly (such as when using the unmodified URL), it returns a JSON object that looks like the following:

Code:
{
    "status": "ok",
    "html": {
        "content": "...",
        "title": "Log in",
        "js": [
            "/js/xf/login_signup.min.js?_v=d53df288"
        ]
    },
    "debug": {
        "time": 0.0064,
        "queries": 4,
        "memory": 2.41
    }
}

With my custom registration button, I'm getting just the HTML without the JSON wrapper and the Content-Type header is different as well.

There doesn't seem to be any setting for this in the controller or the route.

Any ideas why this is happening?
 

Lukas W.

Well-known member
XF will usually send a json response when it detects an ajax request. If there's no specific view class, it's just the page content minus the wrapper and additional json information. I believe this is done via the _xfWithData=1 query value on regular requests.
 
Top