Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Recording a boolean preference from the Application Form

dan39dan39 New
edited July 2008 in Vanilla 1.0 Help
It would be very helpful if someone could write an add-on that adds a checkbox for saving a Yes/No (or 0,1) boolean preference (such as a newsletter subscription, or a "do not send me offers via email" preference) into the application form. The user would also be able to update that preference from their account page.

The add-on wouldn't need to do anything more than that since anyone with admin access to the database can easily export the recorded data in nearly any format directly from their database manager (phpMyAdmin, etc.).

A more advanced version of this proposed add-on would let admins define multiple boolean preferences that can be placed in the database from the admin form (for example "please enter me in this month's sweepstakes")

I know that the "Predefined Attributes" can do this, but it's code is very outdated (it was written for Vanilla 0.9.2) and isn't being maintained anymore. Plus, it crams all of the labels and values into an array in the database, which is really not useful for simple boolean preferences that often need to be extracted and referenced easily. Additionally, it's companion add-on (User Export) to access that data no longer works in the latest release of Vanilla.

Is anyone aware of a more recent add-on that does something similar to this that can achieve this with some modifications?

Any solutions would be greatly appreciated. I would think that many people could find an add-on like this useful.


  • edited May 2007
    WP does something like this with a meta table. You add a field name to the meta_field and the data to the meta_value. Isn't that what the predefined attributes was doing? I started to do this on an extension I was working on but never completed (like so many others).
  • dan39dan39 New
    edited May 2007
    Predefined Attributes seems to be good for jamming lots of custom survey-type data into one table column. But, that's somewhat different from recording important boolean preferences as separate columns.

    As I said before, Predefined Attributes has a companion add on called "User Export" which allows you to export the survey-type array/data into a CSV file. But "User Export" only works in Vanilla 0.9.2. So, the recorded Predefined Attributes data is essentially useless — or at the very least, quite difficult to work with.

    "User Export" probably only needs some minor tweaks (it seems to just be using some deprecated code) but I can't wrap my head around it to bring it up to compatibility with Vanilla 1.0.

    I'm sure it's an easy fix, but I'm not having any luck.
  • edited July 2008
    I've been banging my head against this exact problem the last few days. I've added the preference as per the documentation and it works a treat as a preference, but I'd like to have that preference also available at signup to promote it more.

    So far I've added the code to a delegate that includes the tickbox on the registration form but I can't see how to include the data passed into the user creation SQLBuilder. The line I've been looking at is the last one in the code below, which would be triggered by a "User Manager / PreDataInsert" delegate:

    $SqlBuilder = &$UserManager->DelegateParameters["SqlBuilder"]; $User = &$UserManager->DelegateParameters["User"]; $SqlBuilder->AddFieldNameValue("MyCustomPref", FormatStringForDatabaseInput($User->MyCustomPref));

    but that won't work as rather than a field called 'MyCustomPref', in the latest Vanilla, the preferences are stored in a single field called "preferences" something similar to this:


    The only documentation i can find with regards to updating a preference seems based on the logged in user:

    $UserManager->SwitchUserPreference('MyCustomPref', $Switch);

    How can I port that UserPreference function into something that'll work in the SqlBuilder bit above at user registration? Is the preferences field blank by default, therefore could that SqlBuilder line work like this?

    $SqlBuilder->AddFieldNameValue("Preferences", FormatStringForDatabaseInput("a:3:{s:18:"MyCustomPref";i:1;}"));

    Would there be any side effects to writing that in? And what do the "a:3" and "s:18" bits represent?

    Anyone know the right way of going about this?
This discussion has been closed.