/[cvs]/nfo/php/libs/com.newsblob.phphtmllib/tag_utils/form_utils.inc
ViewVC logotype

Diff of /nfo/php/libs/com.newsblob.phphtmllib/tag_utils/form_utils.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by jonen, Sat Feb 22 21:08:05 2003 UTC revision 1.4 by jonen, Thu May 6 16:27:36 2004 UTC
# Line 255  function form_active_radio( $name, $list Line 255  function form_active_radio( $name, $list
255              }              }
256    
257              $attr["class"] ="form_link";              $attr["class"] ="form_link";
258              $attr["href"] = "#";              $attr["href"] = "javascript:void(0)";
259              $js = "javascript: function check(item){item.click();} check(".$name.".item($i));";              $js = "javascript: function check(item){item.click();} check(".$name.".item($i));";
260              $attr["onclick"] = $js;              $attr["onclick"] = $js;
261    
# Line 356  function form_active_checkbox($name, $te Line 356  function form_active_checkbox($name, $te
356              $js_action .= $onClick;              $js_action .= $onClick;
357          }          }
358    
359          $attributes = array("href"=>"#",          $attributes = array("href"=>"javascript:void(0)",
360                              "onClick"=>$js_action                              "onClick"=>$js_action
361                             );                             );
362    
# Line 435  function form_textarea($name, $value=NUL Line 435  function form_textarea($name, $value=NUL
435   *                             ie   *                             ie
436   *                             array( "test" => "foo")  would give an option   *                             array( "test" => "foo")  would give an option
437   *                             of <option value="foo"> test </option>   *                             of <option value="foo"> test </option>
438     *                            
439     *                  NOTE: this also supports automatic building of
440     *                        the optgroup. Just pass in an array of
441     *                        array("foogroup" => array("name" => "value1",
442     *                                                  "name2" => "value2"),
443     *                              "bargroup" => array("blah" => "foo"));
444     *
445     *                                
446   * @param   mixed  $selected - This can be either a string or an array.   * @param   mixed  $selected - This can be either a string or an array.
447   *                             If its a string then, it will be the selected   *                             If its a string then, it will be the selected
448   *                             option value   *                             option value
# Line 457  function form_select($name, $options=arr Line 465  function form_select($name, $options=arr
465      }      }
466    
467      while (list($label, $value) = each($options)) {      while (list($label, $value) = each($options)) {
468          $selected_value = "";          //see if they wanted an option group
469            if (is_array($value)) {
470          if (is_array($selected)) {              $option = html_optgroup($label);
471              //looks like this is a multiple select box              foreach( $value as $optname => $optvalue ) {
472              //lets see if the value is in the array                  $selected_value = form_select_is_selected($value, $selected);
473              if (in_array($value, $selected)) {                  $option->add(html_option($optvalue, $optname, $selected_value));
                 $selected_value = "SELECTED";  
             }  
         }  
         else {  
             //must be a string  
             if ($value == $selected) {  
                 $selected_value = "SELECTED";  
474              }              }
475            } else {
476                $selected_value = form_select_is_selected($value, $selected);
477                $option = html_option($value, $label, $selected_value);
478          }          }
479    
   
         $attributes = array( "value" => $value, $selected_value );  
         $option = new OPTIONtag( $attributes );  
         $option->push( $label );  
480          $select->push( $option );          $select->push( $option );
481      }      }
482      return $select;      return $select;
483  }  }
484    
485    
486    /**
487     * This function is used by form_select
488     * to determin if a value is selected or not.
489     *
490     * @param string value
491     * @param string selected value
492     * @return voolean
493     */
494    function form_select_is_selected($value, $selected) {
495        $selected_value = false;
496    
497        if (is_array($selected)) {
498            //looks like this is a multiple select box
499            //lets see if the value is in the array
500            if (in_array($value, $selected)) {
501                $selected_value = TRUE;
502            }
503        } else {
504            //must be a string
505            if ($value == $selected) {
506                $selected_value = TRUE;
507            }
508        }
509        return $selected_value;
510    }
511    
512  ?>  ?>

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.4

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed