b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (0.9.x) [ class tree: evocore ] [ index: evocore ] [ all elements ]

Source for file _functions_forms.php

Documentation is available at _functions_forms.php

  1. <?php
  2. /**
  3.  * Fast Form handling
  4.  *
  5.  * b2evolution - {@link http://b2evolution.net/}
  6.  * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
  7.  * @copyright (c)2003-2005 by Francois PLANQUE - {@link http://fplanque.net/}
  8.  *
  9.  * @package evocore
  10.  */
  11. if!defined('DB_USER') ) die'Please, do not access this page directly.' );
  12.  
  13. /**
  14.  * builds an text (or password) input field.
  15.  *
  16.  * {@internal form_text(-)}}
  17.  * @param string the name of the input field
  18.  * @param string initial value
  19.  * @param integer size of the input field
  20.  * @param string label displayed in front of the field
  21.  * @param string note displayed with field
  22.  * @param integer max length of the value (if 0 field_size will be used!)
  23.  * @param string the CSS class to use
  24.  * @param string input type (only 'text' or 'password' makes sense)
  25.  * @return mixed true (if output) or the generated HTML if not outputting
  26.  */
  27. function form_text$field_name$field_value$field_size$field_label$field_note ''$field_maxlength $field_class ''$inputtype 'text' )
  28. {
  29.     if$field_maxlength == )
  30.         $field_maxlength $field_size;
  31.  
  32.     echo '<fieldset>';
  33.     echo '  <div class="label"><label for="'$field_name'">'$field_label':</label></div>';
  34.     echo '  <div class="input"><input type="'$inputtype'" name="'$field_name'" id="'$field_name'" size="'$field_size'" maxlength="'$field_maxlength'" value="'format_to_output($field_value'formvalue'),'"';
  35.     if!empty($field_class) )
  36.     {
  37.         echo ' class="'$field_class,'"';
  38.     }
  39.     echo '/>';
  40.     echo '  <span class="notes">'$field_note'</span></div>';
  41.     echo "</fieldset>\n\n";
  42. }
  43.  
  44. /**
  45.  *
  46.  *
  47.  *
  48.  */
  49. function form_textarea$field_name$field_value$field_rows$field_label$field_note ''$field_cols 50 $field_class '' )
  50. {
  51.     global $img_url;
  52.  
  53.     echo '<fieldset>';
  54.     echo '  <div class="label"><label for="'$field_name'">'$field_label':</label></div>';
  55.     echo '  <div class="input"><fieldset class="input"><img src="'.$img_url.'/blank.gif" width="1" height="1" alt="" /><textarea name="'$field_name'" id="'$field_name'" rows="'$field_rows'"  cols="'$field_cols'"';
  56.     if!empty($field_class) )
  57.     {
  58.         echo ' class="'$field_class,'"';
  59.     }
  60.     echo '>'.$field_value.'</textarea></fieldset>';
  61.     echo '  <span class="notes">'$field_note'</span></div>';
  62.     echo "</fieldset>\n\n";
  63. }
  64.  
  65.  
  66. /*
  67.  * form_text_tr(-)
  68.  */
  69. function form_text_tr$field_name$field_value$field_size$field_label$field_note ''$field_maxlength $field_class '' )
  70. {
  71.     if$field_maxlength == )
  72.         $field_maxlength $field_size;
  73.  
  74.     echo '<tr>';
  75.     echo '  <td align="right"><label for="'$field_name'"><strong>'$field_label':</strong></label></td>';
  76.     echo '  <td><input type="text" name="'$field_name'" id="'$field_name'" size="'$field_size'" maxlength="'$field_maxlength'" value="'format_to_output($field_value'formvalue'),'"';
  77.     if!empty($field_class) )
  78.     {
  79.         echo ' class="'$field_class,'"';
  80.     }
  81.     echo '/>';
  82.     echo '  <small>'$field_note'</small></td>';
  83.     echo "</tr>\n\n";
  84. }
  85.  
  86.  
  87. /*
  88.  * form_select(-)
  89.  */
  90. function form_select(
  91.     $field_name,
  92.     $field_value,
  93.     $field_list_callback,
  94.     $field_label,
  95.     $field_note '',
  96.     $field_class '' )
  97. {
  98.     echo '<fieldset>';
  99.     echo '  <div class="label"><label for="'$field_name'">'$field_label(($field_label != ''':' '')'</label></div>';
  100.     echo '  <div class="input"><select name="'$field_name'" id="'$field_name'"';
  101.     if!empty($field_class) )
  102.     {
  103.         echo ' class="'$field_class,'"';
  104.     }
  105.     echo '>';
  106.     eval$field_list_callback$field_value ) );
  107.     echo '  </select>';
  108.     echo '  <span class="notes">'$field_note'</span></div>';
  109.     echo "</fieldset>\n\n";
  110. }
  111.  
  112.  
  113. /*
  114.  * form_select_object(-)
  115.  *
  116.  * same as select but on cache object
  117.  */
  118.     $field_name,
  119.     $field_value,
  120.     $field_object,
  121.     $field_label,
  122.     $field_note '',
  123.     $allow_none false,
  124.     $field_class '' )
  125. {
  126.     echo '<fieldset>';
  127.     echo '  <div class="label"><label for="'$field_name'">'$field_label':</label></div>';
  128.     echo '  <div class="input"><select name="'$field_name'" id="'$field_name'"';
  129.     if!empty($field_class) )
  130.     {
  131.         echo ' class="'$field_class,'"';
  132.     }
  133.     echo '>';
  134.     $field_object->option_list$field_value$allow_none );
  135.     echo '  </select>';
  136.     echo '  <span class="notes">'$field_note'</span></div>';
  137.     echo "</fieldset>\n\n";
  138. }
  139.  
  140.  
  141. /**
  142.  * Generate set of radio options.
  143.  *
  144.  * {@internal form_radio(-)}}
  145.  * @param string the name of the radio options
  146.  * @param string the checked option
  147.  * @param array of arrays (0: value, 1: label, 2: notes)
  148.  * @param string label
  149.  * @param boolean options on seperate lines (DIVs)
  150.  * @param string notes
  151.  */
  152. function form_radio(
  153.     $field_name,
  154.     $field_value,
  155.     $field_options,
  156.     $field_label,
  157.     $field_lines false,
  158.     $field_notes '' )
  159. {
  160.     echo '<fieldset class="setting">';
  161.     echo '  <div class="label">'$field_label':</div>';
  162.     echo '  <div class="input"><fieldset class="input">';
  163.     foreach$field_options as $loop_field_option )
  164.     {
  165.         if$field_lines echo "<div>\n";
  166.         echo '<label class="radiooption"><input type="radio" class="radio" name="'$field_name'" value="'$loop_field_option[0]'"';
  167.         if$field_value == $loop_field_option[0)
  168.         {
  169.             echo ' checked="checked"';
  170.         }
  171.         echo ' /> '$loop_field_option[1]'</label>';
  172.         ifisset$loop_field_option[2) )
  173.             echo '<span class="notes">'$loop_field_option[2]'</span>';
  174.         if$field_lines echo "</div>\n";
  175.     }
  176.     if!empty$field_notes ) )
  177.     {
  178.         echo '<div class="notes">'.$field_notes.'</div>';
  179.     }
  180.     echo '  </fieldset></div>';
  181.     echo "</fieldset>\n\n";
  182. }
  183.  
  184.  
  185. /**
  186.  * form_checkbox(-)
  187.  * @param string the name of the checkbox
  188.  * @param boolean initial value
  189.  * @param string label
  190.  * @param string note
  191.  * @param string CSS class
  192.  * @param boolean to output (default)  or not
  193.  * @return mixed true (if output) or the generated HTML if not outputting
  194.  */
  195. function form_checkbox$field_name$field_value$field_label$field_note ''$field_class '' )
  196. {
  197.     echo '<fieldset>';
  198.     echo '  <div class="label"><label for="'$field_name'">'$field_label':</label></div>';
  199.     echo '  <div class="input"><input type="checkbox" class="checkbox" name="'$field_name'" id="'$field_name'" value="1"';
  200.     if$field_value )
  201.     {
  202.         echo ' checked="checked"';
  203.     }
  204.     if!empty($field_class) )
  205.     {
  206.         echo ' class="'$field_class,'"';
  207.     }
  208.     echo '/>';
  209.     echo '  <span class="notes">'$field_note'</span></div>';
  210.     echo "</fieldset>\n\n";
  211. }
  212.  
  213.  
  214. /*
  215.  * form_checkbox_tr(-)
  216.  */
  217. function form_checkbox_tr$field_name$field_value$field_label$field_note ''$field_class '' )
  218. {
  219.     echo '<tr>';
  220.     echo '  <td align="right"><label for="'$field_name'"><strong>'$field_label':</label></strong></td>';
  221.     echo '  <td><input type="checkbox" name="'$field_name'" id="'$field_name'" value="1"';
  222.     if$field_value )
  223.     {
  224.         echo ' checked="checked"';
  225.     }
  226.     if!empty($field_class) )
  227.     {
  228.         echo ' class="'$field_class,'"';
  229.     }
  230.     echo ' />';
  231.     echo '  <small class="notes">'$field_note'</small></td>';
  232.     echo "</tr>\n\n";
  233. }
  234.  
  235.  
  236. /*
  237.  * form_info(-)
  238.  */
  239. function form_info$field_label$field_info$field_note '' )
  240. {
  241.     echo '<fieldset>';
  242.     echo '  <div class="label">'$field_label':</div>';
  243.     echo '  <div class="info">'$field_info;
  244.     if!empty($field_note) )    echo '&nbsp; <small class="notes">'$field_note'</small>';
  245.     echo '</div>';
  246.     echo "</fieldset>\n\n";
  247. }
  248.  
  249.  
  250. /*
  251.  * form_info_tr(-)
  252.  */
  253. function form_info_tr$field_label$field_info$field_note '' )
  254. {
  255.     echo '<tr>';
  256.     echo '  <td align="right"><strong>'$field_label':</strong></td>';
  257.     echo '  <td>'$field_info;
  258.  
  259.     if!empty($field_note) )    echo ' <td class="small">'$field_note'</td>';
  260.  
  261.     echo "</td></tr>\n\n";
  262. }
  263.  
  264.  
  265. /**
  266.  * creates a form header and puts GET params of $action into hidden form inputs
  267.  *
  268.  * {@internal form_formstart(-)}}
  269.  */
  270. function form_formstart$action$class ''$name ''$method 'get'$id '' )
  271. {
  272.     if$method == 'get' )
  273.     {
  274.         $action explode'?'$action );
  275.         ifisset($action[1]) )
  276.         // we have GET params in $action
  277.             $getparams preg_split'/&amp;|&/i'$action[1]-1PREG_SPLIT_NO_EMPTY );
  278.         }
  279.         $action $action[0];
  280.     }
  281.  
  282.     echo '<form action="'.$action.'" method="'.$method.'"';
  283.  
  284.     if!empty($name) ) echo ' name="'.$name.'"';
  285.     if!empty($id) ) echo ' id="'.$id.'"';
  286.     if!empty($class) ) echo ' class="'.$class.'"';
  287.  
  288.     echo '>';
  289.  
  290.     ifisset($getparams) )
  291.     {
  292.         foreach$getparams as $param)
  293.         {
  294.             $param explode'='$param );
  295.             ifisset($param[1]) )
  296.             {
  297.                 echo '<input type="hidden" name="'.$param[0].'" value="'.$param[1].'" />';
  298.             }
  299.         }
  300.     }
  301. }
  302.  
  303.  
  304. function form_submit$submit_attribs '' )
  305. {
  306.     ?>
  307.     <fieldset class="submit">
  308.         <fieldset>
  309.             <div class="input">
  310.                 <input type="submit" name="submit" value="<?php echo T_('Save !'?>" class="SaveButton" <?php echo $submit_attribs?> />
  311.                 <input type="reset" value="<?php echo T_('Reset'?>" class="ResetButton" />
  312.             </div>
  313.         </fieldset>
  314.     </fieldset>
  315.     <?php 
  316. }
  317. ?>

Documentation generated on Tue, 20 May 2008 01:54:53 +0200 by phpDocumentor 1.4.2