Fork me on GitHub

trying to make a module : problems with formselectmultiple  Bottom

  • Hi,

    For the first time I am trying to write a module....and i am stuck :(
    In the admin part i am trying to make a form with a dropdown box which show's the types in the database.

    At the moment i have the following code :

    Code

    $pntypes = testmodule_getTypesInfo();
            foreach($pntypes as $k => $v) {
                // Add all types to dropdown-list.
                $typeinfo[] = array('id' => $k,
                                  'metric' => $v);
               
            }
            echo "<BR>";
            print_r($typeinfo);
           
        // end get all types
        $row = array();
        $output->SetOutputMode(_PNH_RETURNOUTPUT);
        $row[] = $output->Text("Type:");
        $row[] = $output->FormSelectMultiple('type_id', $typeinfo,0,1);
        $output->SetOutputMode(_PNH_KEEPOUTPUT);
        $output->SetInputMode(_PNH_VERBATIMINPUT);
        $output->TableAddrow($row, 'left', "top");
        $output->SetInputMode(_PNH_PARSEINPUT);


    As you can see i added an print_r($typeinfo) statement which prints the array to check if it got the data from the database.
    The statement returns the following :

    Code

    array ( [0] => array ( [id] => 1 [metric] => Type1 ) [1] => array ( [id] => 2 [metric] => Type2 ) [2] => array ( [id] => 3 [metric] => Type3 ) )

    which looks correct to me.
    If i open the page it does show the dropdown box. And it shows the correct amount of options (three in this case). However it doesn't give the text in the dropdown box (type1,type2,type3).

    I have been looking at this and trying things for to long...and i can't seem te find the problem.
    Can someone point me in the right direction ?
  • check your HTML source - what is being sent to the browser?
  • oh! it should be this:

    Code

    $typeinfo[] = array('id' => $k,
                                  'name' => $v);
  • Your great thanks :D
    changing metric 2 name did the tric.
  • i got one more question related to this piece of code. Somehow if i submit the form it keeps sending the value "admin" instead of the id of the type.

    Code

    // get all types to display them in a dropdown box
           $pntypes = modulename_getTypesInfo();
             foreach($pntypes as $k => $v) {
                // Add all types to dropdown-list.
                $typeinfo[] = array('id' => $k,
                                  'name' => $v);
            }
            echo "<BR>";
            print_r($typeinfo);
           
        // end get all types
        $row = array();
        $output->SetOutputMode(_PNH_RETURNOUTPUT);
        $row[] = $output->Text("Type:");
        $row[] = $output->FormSelectMultiple('type', $typeinfo,0,1);
        $output->SetOutputMode(_PNH_KEEPOUTPUT);
        $output->SetInputMode(_PNH_VERBATIMINPUT);
        $output->TableAddrow($row, 'left', "top");
        $output->SetInputMode(_PNH_PARSEINPUT);


    The print_r statement still gives the same array as above.

    Code

    array ( [0] => array ( [id] => 1 [name] => Type1 ) [1] => array ( [id] => 2 [name] => Type2 ) [2] => array ( [id] => 3 [name] => Type3 ) )


    The form calls a new function that starts with the following code
    [/code]
    list($uid,
    $quantity,
    $type,
    $reason,
    $dates) = pnVarCleanFromInput( 'uid',
    'quantity',
    'type',
    'reason',
    'dates');
    [/code]

    And if i echo $type just after the arguments are extraced it gives the value "admin".

    I can't figure out where that comes from....:(
  • as 'type' is a very commonly used word for variable names, I suggest you use something else for YOUR variable names. Somepeople prefix ALL there variables with something - like the mod name. That may solve your problem.
  • and thanks again ! Second time you solved it in one guess icon_lol

    wish i thought about that, i checked the code time after time and couldn't find anything.
  • tycho

    ...in one guess
    who's guessing? :D :mrgreen: :mrgreen:
  • apparently your not :D
    The guess that you where guessing is that i know how difficult it can be to help people on a forum without the complete information etc.

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