Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

'Specific newsletters' option in 'newsletter subscription form' page type does not work


Go to End
Reply


12 Posts   6617 Views

Avatar
elijahlofgren

Google Summer of Code Hacker, 222 Posts

21 June 2007 at 4:26am

Edited: 21/06/2007 4:29am

I found a bug last night when trying to help Tatey set up a 'newsletter subscription form' page.

First off, the checkboxes for each Newsletter do not show up under the 'Specific newsletters' option in 'newsletter subscription form' page type.

Instead I get this error:

Notice: Undefined variable: nlCheckboxes in /var/www/silverstripe-gsoc/cms/code/Newsletter/SubscribeForm.php on line 92

I was able to fix that error and make the option show up by changing this line in cms/code/Newsletter/SubscribeForm.php from:
if($newsletterTypes && is_array($newsletterTypes)) {
to:
if($newsletterTypes && is_object($newsletterTypes)) {

The next problem I found was that none of the checkbox selections under the "Specific newsletters" option would be saved unless I made the following change (changing $data['CustomNewsletters'] to $_REQUEST['CustomNewsletters']):
http://www.elijahlofgren.com/silverstripe/diffs/Make-Specific-newsletters-option-work-in-Admin-Panel-only-cms-gsoc-r37164.diff

Then, the checkbox selections were saved in the Admin Panel. I did start getting these errors though:

Error in Ajax evaluator on line 974: invalid flag after regular expression
Notice: Undefined offset: 0 in /var/www/silverstripe-gsoc/cms/code/Newsletter/SubscribeForm.php on line 132

Notice: Undefined variable: has in /var/www/silverstripe-gsoc/sapphire/core/model/ComponentSet.php on line 94

Notice: Undefined variable: has in /var/www/silverstripe-gsoc/sapphire/core/model/ComponentSet.php on line 99

Notice: Undefined variable: has in /var/www/silverstripe-gsoc/sapphire/core/model/ComponentSet.php on line 99

Notice: Undefined variable: has in /var/www/silverstripe-gsoc/sapphire/core/model/ComponentSet.php on line 99

Notice: Undefined variable: removeList in /var/www/silverstripe-gsoc/sapphire/core/model/ComponentSet.php on line 105

Then I tried the frontend, and I got these errors:

Notice: Undefined variable: defaultOption in /var/www/silverstripe-gsoc/sapphire/forms/EditableRadioField.php on line 135

Fatal error: Call to a member function getRecord() on a non-object in /var/www/silverstripe-gsoc/sapphire/forms/CheckboxSetField.php on line 20

I was able to fix that fatal error with this change (adding a if ( is_object($this->form) ) statement):
http://www.elijahlofgren.com/silverstripe/diffs/Fix-CheckboxSetField-getRecord-FATAL-error-sapphire-gsoc-r37164.diff

MAIN ISSUE: However, I was unable to fix a major bug where the "Subscribe to lists" option always shows 1 less Newsletter checkbox than is selected under the "Specific newsletters" option on the backend. I tried for a long time to fix this last night, but was unable to.

Hopefully you will have more success fixing this than I did. ;)

My details:
browser, operating system: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.4) Gecko/20061201 Firefox/2.0.0.4 (Ubuntu-feisty)
web server software, PHP version: Apache/2.2.3 (Ubuntu) PHP/5.2.1
SilverStripe version: gsoc branch revision 37164

Hope this helps,

Elijah Lofgren

Avatar
msantang

Community Member, 41 Posts

23 June 2007 at 3:18am

Thanks i just was having that problem.

but only changing
if($newsletterTypes && is_array($newsletterTypes)) {
to:
if($newsletterTypes && is_object($newsletterTypes)) {

works for me

About the missing Newsletter in the list:

in sapphire/forms/CheckboxSetField.php too

if(is_array($source)){
   //unset($source[0]); <- comment this line
   unset($source['']);
}

Martin

Avatar
elijahlofgren

Google Summer of Code Hacker, 222 Posts

23 June 2007 at 5:49am

Thanks for your help msantang!

I have applied the following changes to the gsoc branches of cms and sapphire:
http://www.elijahlofgren.com/silverstripe/patches/Fix-bug-Specific-newsletters-option-in-newsletter-subscription-form-page-type-does-not-work-cms-sapphire-gsoc-r37301.patch

Here is an explanation of the changes:

------------------------------------------------------------------------
r37304 | elofgren | 2007-06-22 12:46:37 -0500 (Fri, 22 Jun 2007) | 1 line

BUGFIX: Add an is_object($this->form) check to fix 'Fatal error: Call to a member function getRecord() on a non-object' error encountered when viewing a 'newsletter subscription form' page on the frontend. Comment out unset($source[0]) call in order to make all the newsletters selected show up under 'Subscribe to lists'. Thanks to msantang for this fix\! More info: http://www.silverstripe.com/bugs/flat/1675
------------------------------------------------------------------------
r37303 | elofgren | 2007-06-22 12:40:01 -0500 (Fri, 22 Jun 2007) | 1 line

BUGFIX: Change is_array($newsletterTypes) to is_object($newsletterTypes) in order to make the list of newsletters show up under the 'Specific newsletters' option in 'newsletter subscription form' pages and change data['CustomNewsletters'] to _REQUEST['CustomNewsletters'] so that the options will be saved. More info: http://www.silverstripe.com/bugs/reply/1675
------------------------------------------------------------------------

Thanks again,

Elijah

Avatar
msantang

Community Member, 41 Posts

26 June 2007 at 1:21am

I still have problems, in suscription form:

- In CMS if i select 'allNewsletters' and save when i see the form again 'specific newletters' is selected (but in DB 'allnewsletters' = 1)

- if is selected 'allNewsletters' or 'specific newletters' show the newletters checkbox in the form in both case.

- Email type field do not show me the options in form

- if i fill the form and click submit button i get:

Debug (Debug::showError() in line 133 of Debug.php)
msg =
Couldn't run query: SELECT `Group`.*, `Group`.ID, if(`Group`.ClassName,`Group`.ClassName,'Group') AS RecordClassName FROM `Group` WHERE (`ID` IN ()) | You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '))' at line 1
errorLevel =
256

Avatar
elijahlofgren

Google Summer of Code Hacker, 222 Posts

26 June 2007 at 5:30am

> - In CMS if i select 'allNewsletters' and save when i see the form again 'specific newletters' is selected (but in DB 'allnewsletters' = 1)

I was able to fix that bug with this simple change:
http://www.elijahlofgren.com/silverstripe/patches/Fix-bug-AllNewsletters-value-not-being-passed-to-OptionsetField-cms-gsoc-r37360.patch

I've also committed that change to the gsoc branch of cms:
------------------------------------------------------------------------
r37360 | elofgren | 2007-06-25 12:04:10 -0500 (Mon, 25 Jun 2007) | 1 line

BUGFIX: Make value of 'SubscribeForm->AllNewsletters' be passed to 'All newsletters' and 'Specific newsletters' OptionsetField so that 'Specific newsletters' is not always shown as checked even if 'All newsletters' was chosen. Reported here: http://www.silverstripe.com/bugs/flat/1675?showPost=1741#post1741
------------------------------------------------------------------------

- if is selected 'allNewsletters' or 'specific newletters' show the newletters checkbox in the form in both case.

It does not appear that this is a bug. Rather it seems to be a missing feature.

It does seem to make sense that the Newsletter checkboxes shouldn't be shown if "All Newsletters" is checked or just one Newsletter is chosen.
Looking at SubscribeForm_Controller->Form() in cms/code/Newsletter/SubscribeForm.php it seems like the checkboxes will always be shown.

> - Email type field do not show me the options in form

It looks like these need to be added manually yourself. While editing the Form, click the "More options" icon to the right of "Mail format" and you can type an option and click the green "Add option to field" icon.

- if i fill the form and click submit button i get:

Debug (Debug::showError() in line 133 of Debug.php)
msg =
Couldn't run query: SELECT `Group`.*, `Group`.ID, if(`Group`.ClassName,`Group`.ClassName,'Group') AS RecordClassName FROM `Group` WHERE (`ID` IN ()) | You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '))' at line 1
errorLevel =
256

I don't know what version of SilverStripe you are running, but that same type of error happened in the gsoc branch of SilverStripe for a while before it was fixed.

Do you get that same type of error if you go to /admin/security/ and try to add a member to a group?

What version of SilverStripe are you running?

Hope this helps,

Elijah

Avatar
elijahlofgren

Google Summer of Code Hacker, 222 Posts

26 June 2007 at 5:54am

== I caused that SQL error. Sorry! ==

In the case of the problem with the gsoc branch, I made this change in r36670 to fix an error notice in sapphire/security/Member.php
- if($collatedGroups) {
+ if(isset($collatedGroups)) {

That change caused a SQL error which was fixed by mlanthaler who made this change:
-      if(isset($collatedGroups)) {
+      if(count($collatedGroups) > 0) {

Here was his log message:
------------------------------------------------------------------------
r36789 | mlanthaler | 2007-06-13 05:14:47 -0500 (Wed, 13 Jun 2007) | 1 line

Bugfix: The added isset() caused a bug when adding a new member because it produces an invalid SQL statement ("... WHERE (`ID` IN ())").
------------------------------------------------------------------------

So what I would do is open sapphire/security/Member.php and try making this change:

replace this line (if it exists):

if(isset($collatedGroups)) {

with this:

if(count($collatedGroups) > 0) {

This error got into the daily builds by patch posted here:
http://www.silverstripe.com/contributions/flat/1371

Avatar
elijahlofgren

Google Summer of Code Hacker, 222 Posts

26 June 2007 at 7:23am

The latest daily build (silverstripe.2.0.DailyBuild.2007-06-25) does not seem to contain this bug: http://www.silverstripe.com/contributions/flat/1371?showPost=1746#post1746

Cheers,

Elijah

Avatar
msantang

Community Member, 41 Posts

27 June 2007 at 2:14am

Thank you Elijah
It works now.

Go to Top