SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2011
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    advice on how to make a multi select drop down field sticky

    hi everyone

    i have a "multi select drop down field" in a form. i now want to make this imput field sticky i.e for the values that have been previouly selected by a user to show as selected fields.

    it might be best if i show u what i have done so far. i would really appriciate advice on how to proceed.

    PHP Code:
    <?php  
    //initilize the values
        
    $source4='';   $fleunt_lang=''$LANGUANAGE_pref=''
                                  
            
    //return the values from the select box 
                  
    if(isset($_POST['fleunt_lang']))
                          {          
                    
    $lang_pref $_POST['fleunt_lang'];
                    foreach (
    $lang_pref as $country
                        {
    $source1 .= $country.", ";}
                        
    $language_pref substr($source10, -2);
                    
                      
    $LANGUANAGE_pref   mysqli_real_escape_string($dbc,trim($language_pref  ));
                    
                          }

    //place the values into an array 
              
                         
    $arr1 = array(    $LANGUANAGE_pref );
                      
    ?>
        <?php  
      THE IMPUT BOX
      
    //lang_list() is taken from a database of languages-plus their Id


    function  country_list (    )
             {
                 global 
    $dbc;
            
                
    $select "  SELECT  
                           country_id,
                          country  "
    ;
                             
                          
    $from   "    FROM
                countrylist  "
    ;
                
             
    $query $select.$from  ;
                 
    $result mysqli_query ($dbc$query);
             return 
    $result 
                      }  





        
    //i will later attempt to check if the $langauge_id is in the Array-the array was previouly supplied from the returned values above. 
        
      
    echo'       <form action= ""  method="post" name="form_jobsort"    id="form_jobsort "       >
           
                       
                
         
        
             <select name="fleunt_lang[]" id ="fleunt_lang"      multiple="multiple"       size="6"       style="font-family: Tahoma; width: 300px;     font-size: 12pt" >'
    ;
              
        
           
          
    $language_list      =    language_list( );
         
        while  (
    $row mysqli_fetch_array $language_listMYSQLI_ASSOC)) 
            
        {     
            
            
            
    $language_id =   safe_output$row['language_id']) ;
            
    $language  =   safe_output$row['language']) ;
            
            
                

           if (
    in_array($language_id,   $arr1))
                {
                      echo 
    '<option value="' $language_id  .'" selected>' .$language  '</option>';
                }
              else
                {
                echo 
    '<option value="' .$language_id  .'">' $language '</option>';
                }
                            
                
                
         
        } echo
    '</select>'';

    ?>

    </form>
    i am not sure if its clear what i was trying to do. i will explain :

    i was collected the values that were selected by the user when they submitted the form and then placing them in an array so that i could later use the IN_array() funciton to determin whether those values had been previouly selected.

    i.e


    PHP Code:
           if (in_array($language_id,   $arr1))
                {
                      echo 
    '<option value="' $language_id  .'" selected>' .$language  '</option>';
                }
              else
                {
                echo 
    '<option value="' .$language_id  .'">' $language '</option>';
                } 
    i have since been advised that my method of trying to place the submitted values into an array was incorrect and that all i did was to place the returned values into a stirng.

    If, so, does anyone have any advice how i can place the returned values into an array?

    if this method of trying to make the select filed sticky is not the best way to do this, then i would really appriciate some advice on the best way to do this.

    warm regards

    Andreea

  2. #2
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,079
    Mentioned
    53 Post(s)
    Tagged
    0 Thread(s)
    Sorry, I'm still having a little trouble understanding what you're looking to accomplish. It might be best to try to explain high user level what you want to do. Save a users language preference?

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2011
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hello K. Wolfe

    thank you for your responce. i will try and explain more clearly. i have a form field with several field. one of them is a select field like the one below:
    <select multiple="multiple" >
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
    <option value="mercedes">Mercedes</option>
    <option value="audi">Audi</option>
    </select>


    when a user clicks the submit button, i want a way to be able to show the users the values they have just selected.

    i.e

    <select multiple="multiple" >
    <option value="volvo">Volvo</option>
    <option value="saab" selected>Saab</option>
    <option value="mercedes" selected >Mercedes</option>
    <option value="audi">Audi</option>
    </select>

    i hope its clearer now what i was trying to acheive. if not , please tell me and i can show more examples

    warm regards


    Andreea

  4. #4
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,079
    Mentioned
    53 Post(s)
    Tagged
    0 Thread(s)
    Ah, you will then want to utilize a session: http://php.net/manual/en/ref.session.php. This is one way to ensure data will survive an HTTP request.

  5. #5
    SitePoint Enthusiast
    Join Date
    May 2011
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi K Wolfe.

    i am not trying to place the values in a session. i want the values that have been clicked to be highlighed in the form field. i give you an example of an imput filed that has been made sticky;

    PHP Code:
      
                    if(!empty($_POST['last_name'])) {
                 $lastname  =   mysqli_real_escape_string($dbc, trim( ucfirst(strtolower( $_POST['last_name']))));
                     
                     }        
                         
                        
            
                }

    <form>


                <?php echo '<input type="text" name="name"    name="last_name"           size="20" 
            maxlength="80"  style="font-family: Tahoma; width: 380px;  height: 30pt;     font-size: 14pt"
               value="' 
    .  $lastname  '"  />'?>  





    </form>
    you can see from the form above that the imput filed will now be sticky beucase the varable $lastname was filled in by the returned values of the forms.

    i want to do the same thing with the multi select field . i want to be able to highlight the values that have been previouly selected by the user.

    warm regards

    Andreea


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •