Page 1 of 1

Warning in NMS action.do_usersettings.php when unsubscribing to single list

Posted: Sat Mar 17, 2007 10:43 pm
by jptechnical
When a user unsubscribes to a list (unchecks box) then hits submit they get the following above the confirmation text. The confirmation text is fine though.

Code: Select all

Warning: Invalid argument supplied for foreach() in /root/path/public_html/modules/NMS/action.do_usersettings.php on line 46
This does not occur if you check the box and subscribe to a list.

Any ideas?

Re: Warning in NMS action.do_usersettings.php when unsubscribing to single list

Posted: Thu May 17, 2007 5:11 pm
by myshko
It's because there's no validation in the code to cope with the situation where no lists are selected.

The code should spit out an error saying something like 'You need to select at least one list'.

Instead, it's trying to output a 'foreach' command, when there's nothing to foreach.

I'm having the same problem with subscriptions (action.do_create_new_yser.php lines 84 and 121), where a user can uncheck all the lists and the same line is shown.

If I can find a solution I'll post it here also.

Re: action.do_usersettings.php when unsubscribing single list [SOLVED]

Posted: Thu May 17, 2007 5:38 pm
by myshko
Okay,

Found a solution for you, I think. Feel bad hacking through code but this is open source.

As I mentioned above, there's no validation to output an error message if a user de-selects all their lists.

So, we need to put one into action.do_usersettings.php.

As far as I can see, all the validation statements are added at the top of each php file.

So, add this code to line 9 of action.do_udersettings.php

Code: Select all

    
if( !isset($params['lists']) || count($params['lists']) == 0 )
    {
	  $this->_DisplayErrorPage( $id, $params, $returnid,
			      $this->Lang('error_selectonelist'));
    return;
    }
This will output an Error! message and the 'error_selectonelist' from the language file (eng_US.php line 275)

This is a quick fix, the page should remain on the previous one and allow them to check a list and continue, rather than output an error and force them to go back. If can I figure that out and sweeten things I'll post it.

Hope this helps in the meantime.

Re: Warning in NMS action.do_usersettings.php when unsubscribing to single list

Posted: Thu May 17, 2007 6:22 pm
by myshko
I've gotten about as far as my poor reverse engineering will go and need some help.

In ROOT/modules/NMS/action.do_create_new_user.php at line 23 there is the following error condition:

Code: Select all


  if( !isset($params['lists']) || count($params['lists']) == 0 )
    {
      $params['message'] = $this->Lang('error_selectonelist');
      $params['error'] = 1;
      $this->Redirect( $id, $action, $returnid, $params, !$admin );
      return;
    }

This redirects the page using the 'Redirect' command from the CMSmodule (http://www.cmsmadesimple.org/apidoc/CMS/CMSModule.html#Redirect)

Passing the arguments in the url as query strings. This works fine for the subscribe process and outputs the correct error message.

I've tried to include it in action.do_usersettings.php to create a better error output, but it simply redirects to a blank page. When I looked at the string I could see the module setting was missing (in this case, 'usersettings') which when added outputs the right fields. But there's still no error message.

I checked my templates, and the error message condition is still there.

So, my two questions are:

1. How to I make the Redirect command go to the right section of the module 'usersettings'
2. How do I make it output the error message 'error_selectonelist'

Sorry if I'm overlooking something simple or doing something stupid, I have no PHP knowledge at all, just a simple XHTML/CSS monkey.

Thanks in advance...