Fork me on GitHub

FormSelectMultiple  Bottom

  • I'm trying to use the FormSelectMultiple function for one of my forms.

    Could some one post an example of what kind of array it wants for the $data .

    Please? :)

    Thanks
  • But I didn't think FormSelectMultiple was a API function.

    It's in the pnHTML file.
  • pnAPI and pnHTML are both covered at that site, and pnHTML is still an API of sorts.

    --
    Home Page | Find on Facebook | Follow on Twitter
  • /* hi,my form dropdown shows nothing but, say if i have five items in myarray it will have 5 lines,just that i cant see it each element.How to make this work? */

    $myarray = pnModAPIFunc('Conference','admin','userlist');

    print_r($myarray);

    //PRINTED THIS :
    //Array ( [0] => Array ( [uname] => Anonymous ) [1] => Array ( //[uname] => radzee ) [2] => Array ( [uname] => seeker ) )

    //the drop down in my form

    $row[] = $output->FormSelectMultiple('allowed_user_1', $myarray, 0,1);


    //this is the function for the API

    function conference_adminapi_userlist()
    {

    $myarray = array();

    $dbconn =& pnDBGetConn(true);
    $pntable =& pnDBGetTables();


    $userstable = $pntable['users'];
    $userscolumn = &$pntable['users_column'];


    $SQL = "SELECT $userscolumn[uname]
    FROM $userstable
    ORDER BY $userscolumn[uname]";
    $result = $dbconn->Execute($SQL);


    if ($dbconn->ErrorNo() != 0) {
    pnSessionSetVar('errormsg', _GETFAILED);
    return false;
    }

    for (; !$result->EOF; $result->MoveNext()) {
    list($uname) = $result->fields;

    $myarray[] = array('uname' => $uname);

    }

    $result->Close();

    return $myarray;
    }

    //hope somebody can guide me and explain where have i gone wrong
  • pnHTML is legacy code...
    Give a shot to a pnRender style mod...

    I also suggest that if you put only one value per array row, don't save it as an array... or save also the uid...

    either

    Code

    $myarray[] = $uname;
    }


    or

    Code

    $sql = "SELECT   $userscolumn[uid],
                     $userscolumn[uname]
            FROM     $userstable
            ORDER BY $userscolumn[uname]"
    ;

    $result = $dbconn->Execute($sql);

    if ($dbconn->ErrorNo() != 0) {
        pnSessionSetVar('errormsg', _GETFAILED);
        return false;
    }

    for (; !$result->EOF; $result->MoveNext()) {
        list($uid, $uname) = $result->fields;

        $myarray[] = array('uid'   => $uid,
                           'uname' => $uname);

    }


    And lastly, use the bbcode "code" tag as it makes code more readable. wink
  • Thanks for the advice chestnut,
    I still have a problem with FormSelectMultiple,i've saved only uname in the array now it seems only the first letter of each element is shown in the drop down box,how to make it shown in full?

    this is my form field

    $row[] = $output->FormSelectMultiple('allowed_user_1', $myarray, 0, 1, $uname);

    thanks again for the reply.I'll look into pnRender as soon as i finish this.
    by the way,why did it work that way?
  • Some correction about what I said...

    Here would be the working code :

    Code

    $myarray[] = array('id'   => $uname,
                       'name' => $uname);


    or if you are using the uid...

    Code

    $myarray[] = array('id'   => $uid,
                       'name' => $uname);


    The FormSelectMultiple is looking for an id and a name...

    id serves as the value of the option, name serves for the display

    Code

    <option value="WHAT IS IN THE ID">WHAT IS IN THE NAME</option>


    Boy this is old stuff....... hard time remembering it. icon_lol
  • :shock: glad u replied .. i dont know whether i should laugh or just kill myself LOL .. man i tried putting UID in the array and they display fine... when i changed to UNAME it shows only the first character..is it because of FormSelectMultiple only show 1 character?
  • LOL i just asked a super dumb thing man .. it is working now ... cool dude ... thanks .. brain is not prone to details when i'm frustated i guess.

    Quote

    $myarray[] = array('id' => $uname,
    'name' => $uname);


    i get it ... formSelectMultiple needs id,name field ... :D

    thanks chestnut .. problem solved
  • Chestnut!,
    Does postnuke need Anonymous user? ... if it does ... how to exclude it from being show in $myarray ?
  • Well I dont think PN needs that anonymous user account .. coz i deleted it .. and nothing changes except for less 1 user :D .. thank you again chestnut...
  • mmm....... not sure it is wise to delete the anonymous from the user table as it can be of use elsewhere and in perms but all you had to do was removing it from your query.......

    Code

    $sql = "SELECT   $userscolumn[uid],
                     $userscolumn[uname]
            FROM     $userstable
            WHERE    $userscolumn[uid] != '1'
            ORDER BY $userscolumn[uname]"
    ;


    Anonymous user being user uid 1 if I remember correctly.
  • Code

    WHERE    $userscolumn[uid] != '1'


    Thank you for taking the time to answer my question :D It seems like that is the better thing to do.

This list is based on users active over the last 60 minutes.