NewsletterMadeSimple custom fields return empty

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
smithdesign77
Forum Members
Forum Members
Posts: 25
Joined: Mon Jan 02, 2017 10:27 pm

NewsletterMadeSimple custom fields return empty

Post by smithdesign77 »

Hey y'all!

So, meanwhile as I got the mais to send ;D I'm running into the next problem … my custom fields are not populated.
Wherever {$fields.MYFIELD} should be populated I only receive "".

So, first I thought perhaps the variables don't fit (because I uploaded the newsletter recipients and the fields were added automatically … if I remember this right, it's been a while). Hence I deleted the custom fields, re-added them again and typed the extra-field-data manually into the recipients (lucky there weren't too many).
Still no joy. :-\

At some point I figured I'll try to pull all the data what is in the call and put a {get_template_vars} into my message body.
Now I got following data with the newsletter-email:

Code: Select all

… various … other … data … here …

]
$fielddefs (array) = [
   .Anrede (object of type: nms_fielddef) = {   }
   .Vorname (object of type: nms_fielddef) = {   }
   .Nachname (object of type: nms_fielddef) = {   }
]
$subject (string) = MySubject
$username (string) = MyUserName
$email (string) = mymailaddress@example.com

… some … more …other … data …
So, first I thought »Apparently just the variable name had changed due to the upgrade from {$fields} to {$fielddefs}, hence I need to copy {$fielddefs.Andrede} instead of what I used before ({$fields.Anrede})« … but - still no joy. :'(

Okay, now I'm officially confused and ask you guys for a little hint.
The custom fields ARE there (I can clearly see them in the dump from the get_template_vars), but appear to be empty?
I mean - shouldn't there within the brackets be more data then?
Usually?
Like, if I use that in the regular template I see stuff in the second, third and so forth level, right?

Also in the other portion of the transmitted data it goes into the deep (or is that in any way a different kind of data?):

Code: Select all

…
$encoding (string) = utf-8
$message (array) = [
   .messageid (string) = 1
   .uniqueid (string) = 3e66da0f2dfbdeaf1df38c6f7d42b8fb
   .subject (string) = 2020-12-28
   .message (string) = {get_template_vars}
{$fields.Anrede} {$fields.Vorname} {$fields.Name},
this is a test message only.
When I open that recipient dataset I can clearly see the fields populated; they are not resetted or such. Also in the database all the data is there, exactly as it was on the old website with the older version of NMS.
So, whatever I enter there, remains there. Seems to be fully functional.

But still I can't pull the data, neither with {$fields} nor with {$fielddefs} and not even with god-mode {get_template_vars}?
Gee. I can't help my self any more. :(

Thanks for your help! :)
smithdesign77
Forum Members
Forum Members
Posts: 25
Joined: Mon Jan 02, 2017 10:27 pm

Re: NewsletterMadeSimple custom fields return empty

Post by smithdesign77 »

Alright, I got it to give me some more info.
When my message said:

Code: Select all

===
{$fields|print_r}
===
it returned in the email as:

Code: Select all

===
1
===
But when my message said:

Code: Select all

===
{foreach from=$fielddefs item=fields name=item}
  {$fields|print_r}
{/foreach}
...eof foreach
===
Then it returned in the email as:

Code: Select all

===
  nms_fielddef Object
(
    [_data:nms_fielddef:private] => Array
        (
            [id] => 4
            [type] => textbox
            [name] => Anrede
            [prompt] => Ansprache Sehr geeh
            [order] => 1
            [optiontext] => 
            [required] => 1
        )

)
1
  nms_fielddef Object
(
    [_data:nms_fielddef:private] => Array
        (
            [id] => 5
            [type] => textbox
            [name] => Vorname
            [prompt] => Vorname
            [order] => 2
            [optiontext] => 
            [required] => 1
        )

)
1
  nms_fielddef Object
(
    [_data:nms_fielddef:private] => Array
        (
            [id] => 6
            [type] => textbox
            [name] => Nachname
            [prompt] => Nachname
            [order] => 3
            [optiontext] => 
            [required] => 1
        )

)
1

...eof foreach
===
Hence there IS accessible data, however even with a foreach and print_r I do not receive the actual values, but only the "telemetrics" (about what kind of field it is, what name it has, if it is required to fill, etc). And $fields as mentioned in the documentation does not return anything at all.
I'm not very familiar with print_r, but if I had to guess, I'd think that the values should be given between the closing brackets at the end of each field:

Code: Select all

            …ired] => 1
        )
   VALUE
)
But I may be mistaking about that - I just don't have the experience. ???

Again, any help is greatly appreciated. I feel kinda like at the very, very end of my capabilities.
Right now I'm thinking of creating a php driven database request in the message template to draw the data from there … but this would be very tricky, because the in that job given unique_id for the user is not the user_id of the table where the user data is stored in … so I first had to get the userid from module_nms_users and then search for that userid in the table nms_user_data … and perhaps I'm a somewhat average-good designer, but certainly I am the worst coder somebody could ever hire and most defiantly I'd crash the whole thing. ;D

Again: Thank you for your suggestions and help!
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3483
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: NewsletterMadeSimple custom fields return empty

Post by velden »

The $fields variable is expected to be different from the $fielddefs variable.

IF the $fields variable exists it has this form:

Array ( [test] => test-value )

So it's an array with the keys being the field name and the value being the field value.

{$fields.test} (in my example) should just output: test-value.

I noticed that during sending a test email from the Compose Message page there will be no custom fields for the user, hence the $fields variable is not set then. I haven't checked a 'normal' job.
smithdesign77
Forum Members
Forum Members
Posts: 25
Joined: Mon Jan 02, 2017 10:27 pm

Re: NewsletterMadeSimple custom fields return empty

Post by smithdesign77 »

Thank you Velden!

What you described, was exactly how id did work for many years. Actually I cannot recall that this had ever not worked, until just now. :-\
The background is, that I had to upgrade a very, very old charity-like website, that uses newsletters like three or four times a year. Hence actually it wouldn't need to work at all — also I could tell the few recipients that the feature of personalized newsletters was discontinued and from now on every newsletter just starts with "Dear Ladies and Gentlemen" instead of "Dear Mrs. Johnson".
However, as the doc states it should be possible - and I would like to use it, just like until the present day.

So I tried your suggestion and sent a newsletter with following content (by the way: text only, no HTML):

Code: Select all

fields.Name
===
{$fields.Anrede}
{$fields.Vorname}
{$fields.Nachname}
===
And received following email:

Code: Select all

fields.Name
===



===
So it returns nothing. :'(

Also, just for safety, I just tested following message:

Code: Select all

fields.Name
===
{$fields.Anrede}
{$fields.Vorname}
{$fields.Nachname}
===

fields.Name->value
===
{$fields.Anrede->value}
{$fields.Vorname->value}
{$fields.Nachname->value}
===
And then received following email:

Code: Select all

fields.Name
===



===

fields.Name->value
===



===
I am positive, that the fields names (Anrede, Vorname, Nachname) are correct; not only because I copied them from the backend, but also as I mentioned in my first post (viewtopic.php?p=346634#p346634) I received the names in that email with the get_template_vars and also on other occasions. Therefore {$fields.Anrede} etc. must be correct.
By the way: Using lowercase characters like {$fields.anrede} led it to error and abort — so I assume it is case-sensitive.

I really don't want to say it ought to be a bug but I wouldn't know what else I could try or do or what I have done wrong.
Like I said before the values are present in the database and can be edited in the backend with the recipients too. The data that is stored is nothing unusual, no special characters or such; my personal profile where I recieve this test emails doesn't even contain a Umlaut like ä, ü, ö or such.

So if there is any kind of protocol I could activate, debugging, system information, any other further Information, whatever - I'd really love to provide any useable information or find the problem myself. I'm stuck. In case this was interesting (I doubt it - but I'm not a coder :P ): It runs on PHP 7.3.23 and in the system information I got most of the checks green. The site as such works without any other issues.

Thanks again! :)
smithdesign77
Forum Members
Forum Members
Posts: 25
Joined: Mon Jan 02, 2017 10:27 pm

Re: NewsletterMadeSimple custom fields return empty

Post by smithdesign77 »

Hallo again,

so, after writing an UDT, in hope I could extract the variables from the database by rendering the UDT within the message body (which, by the didn't work, only did in the front-end) I figured something I cannot grasp (as a designer, not a coder) and therefore ask for your assistance.

I figured that the answers from the database also couldn't be addressed explicitly (at least I couldn't) because it has been an object and within the object again arrays. So I converted the object into an array to then get the data I needed, like this:

Code: Select all

$db = cmsms()->GetDb();
$getuserid = ("SELECT `userid` FROM `".cms_db_prefix()."module_nms_users` WHERE `email` = \"$email\"");
$uid = $db->Execute($getuserid);
if(!$uid) { echo 'DB error: '. $db->ErrorMsg()."<br/>"; };
$uidarray = (array) $uid;
$uidarray = array_values($uidarray);
$thisuserid = $uidarray[2]["userid"];
// echo $thisuserid;
Please don't burn me - this took me about a full working day of try&error. Most probably this is a very bad piece of code. :'(
Anyway, I've just seen that my output I get from the email body where I state

Code: Select all

{foreach from=$fielddefs item=fields name=item}
  {$fields|print_r}
{/foreach}
also is stated to be an object with an array iside it:

Code: Select all

  nms_fielddef Object
(
    [_data:nms_fielddef:private] => Array
        (
            [id] => 4
            [type] => textbox
So, my question is: May this be, that I need to convert the object here also first into an array, to then address the data I want, to print it in my email (like $var.NameOfVar)?
I'm working on this for so long now and I feel I'm getting close to the answer to finally get this thing done and personalized fields to work! ;D
So, I greatly appreciate your support!
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3483
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: NewsletterMadeSimple custom fields return empty

Post by velden »

Looking at the code of NMS (again) it seems there's a difference between sending a test email and sending a real job.

Did you test sending a job to a real list?
smithdesign77
Forum Members
Forum Members
Posts: 25
Joined: Mon Jan 02, 2017 10:27 pm

Re: NewsletterMadeSimple custom fields return empty

Post by smithdesign77 »

Thank you Velden, for coming back on this.
Indeed I only sent a test mail with NMS once ever and soon figured that fields are not processed at all (what totally makes sense while one doesn't choose a user for the test run, but only a recipient address). So if at all I'd use this only to quickly see how the mail is rendered with different mail clients — and this is how I see this function: a method to send a QUICK message for testing without ruining through the background job Manager.

Actually I'm at the end of upgrading a quite old site from the 1.x branch that uses newsletters. I'm done with all, it's just the newsletter failing.
To make sure it's not about an error in the upgrade I did a vanilla installation with the newest versions of the core and NMS but ran into the same problem.

In the test installation I currently have one list with one user and can only access the variables as I posted a few days ago. If that would help any further I'd be happy to set up an additional user account or provide the system overview information from the backend or whatever else (though I can't imagine that the issue lies in the server config).

Thank you for helping me!
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3483
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: NewsletterMadeSimple custom fields return empty

Post by velden »

Looked further into the code and I now think it's a bug indeed.
There's a method to preload the user fields but it's never called as far as I can see.

I compared latest version with 2.12.2 and if seems to do things really different there.
smithdesign77
Forum Members
Forum Members
Posts: 25
Joined: Mon Jan 02, 2017 10:27 pm

Re: NewsletterMadeSimple custom fields return empty

Post by smithdesign77 »

Thank you Velden!

That was what I thought all along - but over the time reading into some posts (I can't be much of help unfortunately in terms of coding) I figured that a lot of times supposed "bugs" in the end were actually not really bugs, but due to misusage, misconfiguration, server settings and what not else. Hence I didn't file a bug report but seeked support first — so somebody with actual skills could decide over this. ;D

Well, while the last release was a little over two years ago and the project marked to be "stale" — do you think there is a chance the bug (now that you said it, I will too ;D ) will be fixed at some time … or would you rather recommend looking for an other, external tool?

I'm well willing to contribute, but I guess that the costs will exeed my ressources (I have no clue at all if this is "just" a single line or a complete rewrite).

Thanks again! :)
JamesT
Forum Members
Forum Members
Posts: 175
Joined: Tue Sep 08, 2015 10:41 am

Re: NewsletterMadeSimple custom fields return empty

Post by JamesT »

Perhaps of interest: viewtopic.php?p=347101
Post Reply

Return to “Modules/Add-Ons”