Galen-
I can update the wiki shortly (the big area that’s still missing is reading data BACK from the normalized db structure... that’s the other plugin I still need to write)... I’ve accomplished the feat of generating the multi-select based on the rows in one of my tables for my OWN form, but I haven’t used this to tie into WebLoginPE’s automatic handling. I’m debating whether it’s easier to go the route you’re looking at (i.e. priming the pump for WebLoginPE’s inputHandler), or if it’s better to write my own form generation code that handles populating values. One deciding factor might be WebLoginPE’s apparent inability to specify default values. Anyhow...
I’ve put the following function in a file on my web server, and then I have a Snippet that includes that file and executes the one function (I know... it’s more or less the same thing). But here’s my example (I’m using mysqli for my db connections, so you may need to install the php-mysqli package):
function list_animals_as_form_options() {
/*
INPUT: none
OUTPUT: String consisting of form elements for a multiple value drop down form, e.g.
<option value ="dogs_cats">Dogs & Cats</option>
<option value ="frongs_toads">Frogs & Toads</option
*/
$form_contents = '';
$link = connect_db('name_of_my_db_handle');
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$sql = "SELECT animal, description FROM animals";
if ($result = $link->query($sql)) {
while ($row = $result->fetch_object()) {
$form_contents .= '<option value ="' . htmlentities($row->genre) . '">'. htmlentities($row->description) .'</option>';
}
}
$link->close();
return $form_contents;
}
Please note that I’m referencing another file that contains my database connection functions. THAT file and the connect_db() function is formatted as I outlined in another article:
http://www.fireproofsocks.com/php/preparing-mysql-statements-in-php-5/
The function above won’t work exactly for populating the WebLoginPE Snippet call... you’ll have to adjust the output format to match what WebLoginPE expects, i.e. something like:
Favorite Colors:userFavoriteColors:favorite_colors:select multiple:Red(ff0000),Orange(ff9900),Green(66ff00),Black(000000)
I might change my WebLoginPE Snippet call to something like:
[!WebLoginPE? &type=`profile` &profileTpl=`profileTpl`
&customFields=`first_name,last_name,favorite_colors`
&inputHandler=`Favorite Colors:userFavoriteColors:favorite_colors:select multiple:[[Populate_Values]]`!]
There can be some issues if you nest Snippets like this. I think I read somewhere that you have to alternate [[cached]] and [!un-cached!]. There are couple pages on the Wiki about this I think:
http://wiki.modxcms.com/index.php/Snippet_call_anatomy
Another option is PHx... I haven’t used it myself yet, but I think it’s built for precisely this type of thing:
http://wiki.modxcms.com/index.php/PHx
Hope this helps. This post is waaaay to long for the wiki, I think... sorry for the length. If I had more time, it’d be shorter.