Can I dynamicly populate hidden attributes on a Subscribe page?

I have a Subscribe pages which includes some attributes which are hidden, but I’d like to populate one or more of them with some dynamic content, ideally from php.

Is there a way I can do that without hacking phplist core files?

I’m prepared to do that if I have to but would prefer a solution which would survive a phplist upgrade.

Thanks.

@Gerard Depending on the complexity you might be able to do it in a plugin.

Method displaySubscriptionChoice() allows a plugin to add fields to a subscribe form when it is displayed. You can add hidden fields with your calculated values for the attributes. When submitted those values update the user attribute table values.
That this works might just be luck, because there are then two instances of the hidden fields - one added by phplist and the second by the plugin. In my test though it was the second one that was used.

A more reliable way might be use the validateSubscriptionPage() method which is called when the form is submitted. The plugin can overwrite the submitted values held in $_POST for the attributes with calculated values. For example

    if (isset($_POST['attribute8'])) {
        $_POST['attribute8'] = 'new value ' . rand(0, 100);
    }

If you look at any of the captcha plugins, which use both of these methods, then you might get a better idea whether it will work.

1 Like