Login.Register redirects to blank page when using posthooks

Hello,
I am using the Login.Register extra for my website’s registration page, and when I add a posthook to the chunk, the form’s submit button redirects to a blank page. Without any posthooks, the chunk works as it should, and a user is able to register, is sent an activation email, and is redirected to the email verification page. I want to use a posthook to send another email to an admin to notify them of the new user sign up, but when I add the posthook to send the second email, both emails successfully send to the new user and the admin, however the user is redirected to a blank page instead of the email verification page and the following error is logged:

PHP Fatal error:  Uncaught Error: Call to a member function get() on array in /home4/zwyxwmmy/public_html/core/components/login/processors/register.php:413

I also tried using the f12 network tab to try to inspect the requests being sent when I submit the form, and I see that there is a POST request with a 500 error and a GET request to the website’s 404 page.

Here is the Register chunk that I am using:

[[!Register?
    &submitVar=`registerbtn`
    &activationResourceId=`***`
    &activationEmailTpl=`form-activiation-email-tpl`
    &activationEmailSubject=`***`
    &errTpl=`<p>ERROR</p>`
    &submittedResourceId=`***`
    &usergroups=`***`
    &validate=`nospam:blank,
  username:required,
  email:password_confirm=^username^,
  password:required:minLength=^6^,
  password_confirm:password_confirm=^password^,
  fullname:required`
    &placeholderPrefix=`reg.`
    &postHooks=`hookAdminEmail`
]]

And this is the code from the hookAdminEmail snippet:

<?php
$headers .= "From: ***\n"; 
$headers .= "BCC:\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\n"; //

$message = 'Hi, a new User signed up: '.$hook->getValue('username')
 . ' with email '.$hook->getValue('email').'.';

$to = "***";
$subject = "New User Signed Up";

if (mail($to, $subject, $message, $headers)) {
    return true;
} else {
    return false;
}

However I believe that this error occurs regardless of what code is in the snippet, as I have tried out making the only code in the snippet the line return true; to see if the page would display, but even with that simple snippet a blank page and logged error were returned from submitting the form.

Has anyone encountered a similar problem where posthooks stop a page from properly redirecting? Any help would be greatly appreciated.

Try making $headers an array.

I think your experiment with “return true” may have failed because of either the MODX cache or your browser’s cache.

Looking at the code, it appears that you also need this in your Register tag:

&persistParams=`1`

Hi bobray, Thank you very much for your response.

I added the persistParams parameter to my register tag, but the form still redirects me to a blank page.

I tried making $headers into an array, but after changing it the second email is now sent to spam and the from address appears to be a bluehost address rather than the address that I specified in the “From” $headers element.

Here is my updated code:

Register:

[[!Register?
    &submitVar=`registerbtn`
    &activationResourceId=`21`
    &activationEmailTpl=`form-activiation-email-tpl`
    &activationEmailSubject=`Message from Iconically: Thanks for Registering! Please activate your account.`
    &errTpl=`<p>ERROR</p>`
    &submittedResourceId=`20`
    &usergroups=`2`
    &validate=`nospam:blank,
  username:required,
  email:password_confirm=^username^,
  password:required:minLength=^6^,
  password_confirm:password_confirm=^password^,
  fullname:required`
    &persistParams=`1`
    &placeholderPrefix=`reg.`
    &postHooks=`hookAdminEmailTEST`
]]

hookAdminEmailTEST:

<?php
$headers = [
    "From: ***\n",
    "BCC:\n",
    "Content-Type: text/html; charset=iso-8859-1\n"
    ];


$message = 'Hi, a new User signed up: '.$hook->getValue('username')
 . ' with email '.$hook->getValue('email').'.';

$to = '***';
$subject = "New User Signed Up";

if (mail($to, $subject, $message, $headers)) {
    return true;
} else {
    return false;
}

I tried submitting the form with the newline character in each $header array element and without the character in each, but the email with the cryptic from address was sent to the admin user’s spam in both cases.

Do you have any other suggestions as to how I might be able to get the form to successfully redirect the user after firing the posthook?

Is this MODX 3? There is a problem now with redirects and posthooks due to a change in MODX 3 (that I haven’t yet figured out).

Try setting the property &redirectUnsetDefaultParams to 1 for a temporary fix.

Also see this post:

Make sure you don’t have a password manager that might be filling in the hidden spam field,

Thank you for all of the great responses! After changing the redirectUnsetDefaultParams parameter to 1 I was successfully redirected and an email was sent to both the user and email.

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.