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: 18
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: 18
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: 3322
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: 18
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! :)
Post Reply

Return to “Modules/Add-Ons”