b2evolution PHP Cross Reference Blogging Systems

Source: /inc/_core/ui/forms/_form.funcs.php - 327 lines - 9594 bytes - Summary - Text - Print

Description: This file implements Fast Form handling functions. This file is part of the evoCore framework - {@link http://evocore.net/} See also {@link http://sourceforge.net/projects/evocms/}.

   1  <?php
   2  /**
   3   * This file implements Fast Form handling functions.
   4   *
   5   * This file is part of the evoCore framework - {@link http://evocore.net/}
   6   * See also {@link http://sourceforge.net/projects/evocms/}.
   7   *
   8   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}
   9   * Parts of this file are copyright (c)2004-2005 by Daniel HAHLER - {@link http://thequod.de/contact}.
  10   *
  11   * {@internal License choice
  12   * - If you have received this file as part of a package, please find the license.txt file in
  13   *   the same folder or the closest folder above for complete license terms.
  14   * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
  15   *   then you must choose one of the following licenses before using the file:
  16   *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
  17   *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
  18   * }}
  19   *
  20   * {@internal Open Source relicensing agreement:
  21   * Daniel HAHLER grants Francois PLANQUE the right to license
  22   * Daniel HAHLER's contributions to this file and the b2evolution project
  23   * under any OSI approved OSS license (http://www.opensource.org/licenses/).
  24   * }}
  25   *
  26   * @package evocore
  27   *
  28   * @deprecated All those functions should be handled by the {@link Form Form class}.
  29   *
  30   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  31   * @author blueyed: Daniel HAHLER.
  32   * @author fplanque: Francois PLANQUE.
  33   *
  34   * @version $Id: _form.funcs.php 6136 2014-03-08 07:59:48Z manuel $
  35   */
  36  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  37  
  38  
  39  /**
  40   * Builds a text (or password) input field.
  41   *
  42   * @deprecated Deprecated by (@link Form::text_input())
  43   *
  44   * @param string the name of the input field
  45   * @param string initial value
  46   * @param integer size of the input field
  47   * @param string label displayed in front of the field
  48   * @param string note displayed with field
  49   * @param integer max length of the value (if 0 field_size will be used!)
  50   * @param string the CSS class to use
  51   * @param string input type (only 'text' or 'password' makes sense)
  52   * @param boolean display (default) or return
  53   * @return mixed true (if output) or the generated HTML if not outputting
  54   */
  55  function form_text( $field_name, $field_value, $field_size, $field_label, $field_note = '',
  56                                          $field_maxlength = 0 , $field_class = '', $inputtype = 'text', $output = true  )
  57  {
  58      if( $field_maxlength == 0 )
  59          $field_maxlength = $field_size;
  60  
  61      // question: is it necessary to enclose each field in a fieldset.
  62      // fplanque> YES, for CSS
  63      // shouldn't there be a fieldset for a set of field (i.e. all fields
  64      // in the form)?
  65      // fplanque>> Create a new 'simple' layout if this is what you want
  66  
  67      $r = "<fieldset>\n"
  68              .'<div class="label"><label for="'.$field_name.'">'.$field_label.":</label></div>\n"
  69              .'<div class="input"><input type="'.$inputtype.'" name="'.$field_name
  70              .'" id="'.$field_name.'" size="'.$field_size.'" maxlength="'.$field_maxlength
  71              .'" value="'.format_to_output($field_value, 'formvalue').'"';
  72      if( !empty($field_class) )
  73      {
  74          $r .= ' class="'.$field_class.'"';
  75      }
  76      $r .= " />\n";
  77  
  78      if( !empty( $field_note ) )
  79      {
  80          $r .= '<span class="notes">'.$field_note.'</span>';
  81      }
  82  
  83      $r .= "</div>\n</fieldset>\n\n";
  84  
  85      if( $output )
  86      {
  87          echo $r;
  88          return true;
  89      }
  90      else
  91      {
  92          return $r;
  93      }
  94  }
  95  
  96  /**
  97   * Display a select field and populate it with a callback function.
  98   *
  99   * @deprecated Deprecated by {@link Form::select_input()}
 100   *
 101   * @param string field name
 102   * @param string default field value
 103   * @param callback callback function
 104   * @param string field label to be display before the field
 105   * @param string note to be displayed after the field
 106   * @param string CSS class for select
 107   * waltercruz> still used by mtimport
 108   */
 109  function form_select(
 110      $field_name,
 111      $field_value,
 112      $field_list_callback,
 113      $field_label,
 114      $field_note = '',
 115      $field_class = '' )
 116  {
 117      echo '<fieldset>';
 118      echo '  <div class="label"><label for="', $field_name, '">', $field_label, (($field_label != '') ? ':' : ''), '</label></div>';
 119      echo '  <div class="input"><select name="', $field_name, '" id="', $field_name, '"';
 120      if( !empty($field_class) )
 121      {
 122          echo ' class="', $field_class,'"';
 123      }
 124      echo '>';
 125  
 126      // call the callback function:
 127      $field_list_callback( $field_value );
 128  
 129      echo '  </select>';
 130      echo '  <span class="notes">', $field_note, '</span></div>';
 131      echo "</fieldset>\n\n";
 132  }
 133  
 134  
 135  /**
 136   * Display a select field and populate it with a cache object.
 137   *
 138   * @deprecated Deprecated by (@link Form::select_object())
 139   *
 140   * @param string field name
 141   * @param string default field value
 142   * @param DataObjectCache Cache containing values for list (get_option_list() gets called on it)
 143   * @param string field label to be display before the field
 144   * @param string note to be displayed after the field
 145   * @param boolean allow to select [none] in list
 146   * @param string CSS class for select
 147   * waltercruz> still used by mtimport
 148   */
 149  function form_select_object(
 150      $field_name,
 151      $field_value,
 152      & $field_object,
 153      $field_label,
 154      $field_note = '',
 155      $allow_none = false,
 156      $field_class = '' )
 157  {
 158      echo '<fieldset>';
 159      echo '  <div class="label"><label for="', $field_name, '">', $field_label, ':</label></div>';
 160      echo '  <div class="input"><select name="', $field_name, '" id="', $field_name, '"';
 161      if( !empty($field_class) )
 162      {
 163          echo ' class="'.$field_class.'"';
 164      }
 165      echo '>';
 166      echo $field_object->get_option_list( $field_value, $allow_none );
 167      echo '  </select>';
 168      echo '  <span class="notes">'.$field_note.'</span></div>';
 169      echo "</fieldset>\n\n";
 170  }
 171  
 172  /**
 173   * form_checkbox(-)
 174   *
 175   * @deprecated Deprecated by (@link Form::checkbox())
 176   *
 177   * @param string the name of the checkbox
 178   * @param boolean initial value
 179   * @param string label
 180   * @param string note
 181   * @param string CSS class
 182   * @param boolean to output (default)  or not
 183   * @return mixed true (if output) or the generated HTML if not outputting
 184   * waltercruz > still used by mtimport
 185   */
 186  function form_checkbox( $field_name, $field_value, $field_label, $field_note = '',
 187                                                  $field_class = '', $output = true )
 188  {
 189      $r = "<fieldset>\n"
 190              .'<div class="label"><label for="'.$field_name.'">'.$field_label.":</label></div>\n"
 191              .'<div class="input"><input type="checkbox" class="checkbox" name="'.$field_name.'" id="'
 192              .$field_name.'" value="1"';
 193      if( $field_value )
 194      {
 195          $r .= ' checked="checked"';
 196      }
 197      if( !empty($field_class) )
 198      {
 199          $r .= ' class="'.$field_class.'"';
 200      }
 201      $r .= " />\n"
 202                  .'<span class="notes">'.$field_note."</span></div>\n"
 203                  ."</fieldset>\n\n";
 204  
 205      if( $output )
 206      {
 207          echo $r;
 208          return true;
 209      }
 210      else
 211      {
 212          return $r;
 213      }
 214  }
 215  
 216  /**
 217   * form_info(-)
 218   *
 219   * @deprecated Deprecated by (@link Form::info_field())
 220   * @internal Tblue> Still used by gettext/staticfiles.php
 221   */
 222  function form_info( $field_label, $field_info, $field_note = '' )
 223  {
 224      echo '<fieldset>';
 225      echo '  <div class="label">', $field_label, ':</div>';
 226      echo '  <div class="info">', $field_info;
 227      if( !empty($field_note) )
 228      {
 229          echo '&nbsp; <small class="notes">', $field_note, '</small>';
 230      }
 231      echo '</div>';
 232      echo "</fieldset>\n\n";
 233  }
 234  
 235  /**
 236   * Builds a form header and puts GET params of $action into hidden form inputs
 237   *
 238   * @deprecated Deprecated by (@link Form::begin_form())
 239   * waltercruz> still used by inc/widgets/widgets/_coll_search_form.widget.php
 240   */
 241  function form_formstart( $action, $class = '', $name = '', $method = 'get', $id = '' )
 242  {
 243      if( $method == 'get' )
 244      {
 245          $action = explode( '?', $action );
 246          if( isset($action[1]) )
 247          { // we have GET params in $action
 248              $getparams = preg_split( '/&amp;|&/i', $action[1], -1, PREG_SPLIT_NO_EMPTY );
 249          }
 250          $action = $action[0];
 251      }
 252  
 253      echo '<form action="'.$action.'" method="'.$method.'"';
 254  
 255      // this is not xhtml strict, see: http://forums.b2evolution.net//viewtopic.php?t=8475
 256      // if( !empty($name) ) echo ' name="'.$name.'"';
 257      if( !empty($id) ) echo ' id="'.$id.'"';
 258      if( !empty($class) ) echo ' class="'.$class.'"';
 259  
 260      echo '>';
 261  
 262      if( isset($getparams) )
 263      { // These need to be wrapped in a div to validate xhtml strict
 264          echo '<div>';
 265          foreach( $getparams as $param)
 266          {
 267              $param = explode( '=', $param );
 268              if( isset($param[1]) )
 269              {
 270                  echo '<input type="hidden" name="'.$param[0].'" value="'.$param[1].'" />';
 271              }
 272          }
 273          // close the div
 274          echo '</div>';
 275      }
 276  }
 277  
 278  
 279  /**
 280   * Builds a textarea field.
 281   *
 282   * @deprecated Deprecated by (@link Form::textarea_input())
 283   *
 284   * @param string the name of the input field
 285   * @param string initial value
 286   * @param integer rows of the textarea field
 287   * @param string label displayed in front of the field
 288   * @param array params
 289   */
 290  function form_textarea( $field_name, $field_value, $field_rows, $field_label, $field_params = array() )
 291  {
 292  
 293      $textarea_rows = '';
 294      if( !empty( $field_rows ) )
 295      {
 296          $textarea_rows = ' rows="'.$field_rows.'"';
 297      }
 298  
 299      $textarea_cols = '';
 300      if( !empty( $field_params['cols'] ) )
 301      {
 302          $textarea_cols = ' cols="'.$field_params['cols'].'"';
 303      }
 304  
 305      $textarea_class = '';
 306      if( !empty( $field_params['class'] ) )
 307      {
 308          $textarea_class = ' class="'.$field_params['class'].'"';
 309      }
 310  
 311      $r = "<fieldset>\n"
 312              .'<div class="label"><label for="'.$field_name.'">'.$field_label.":</label></div>\n"
 313              .'<div class="input"><textarea name="'.$field_name.'" id="'.$field_name.'"'.$textarea_rows.$textarea_cols.$textarea_class.'>'
 314              .format_to_output($field_value, 'formvalue')
 315              .'</textarea>'."\n";
 316  
 317      if( !empty( $field_params['note'] ) )
 318      {
 319          $r .= '<span class="notes">'.$field_params['note'].'</span>';
 320      }
 321  
 322      $r .= "</div>\n</fieldset>\n\n";
 323  
 324      echo $r;
 325  }
 326  
 327  ?>

title

Description

title

Description

title

Description

title

title

Body