[ Index ]
 

Code source de b2evolution 2.1.0-beta

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/blogs/inc/_core/ui/forms/ -> _form.funcs.php (source)

   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-2007 by Francois PLANQUE - {@link http://fplanque.net/}

   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,v 1.1 2007/06/25 10:59:02 fplanque Exp $

  35   */
  36  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  37  
  38  
  39  /**

  40   * Start an field group.

  41   *

  42   * Fieldset with legend.

  43   *

  44   * @deprecated Deprecated by (@link Form::begin_fieldset())

  45   */
  46  function form_groupstart( $title = '' )
  47  {
  48      echo "<fieldset>\n"
  49                  .'<legend>'.$title."</legend>\n";
  50  }
  51  
  52  
  53  /**

  54   * End an field group.

  55   *

  56   * Fieldset with legend.

  57   *

  58   * @deprecated Deprecated by (@link Form::end_fieldset())

  59   */
  60  function form_groupend( $title = '' )
  61  {
  62      echo "</fieldset>\n";
  63  }
  64  
  65  
  66  /**

  67   * Start an input field.

  68   *

  69   * A field is a fielset containing a label div and an input div.

  70   *

  71   * @deprecated Deprecated by (@link Form::begin_field())

  72   */
  73  function form_fieldstart( $field_name, $field_label )
  74  {
  75      return "<fieldset>\n"
  76              .'<div class="label"><label for="'.$field_name.'">'.$field_label.":</label></div>\n"
  77              .'<div class="input">';
  78  }
  79  
  80  /**

  81   * End an input field.

  82   *

  83   * A field is a fieldset containing a label div and an input div.

  84   *

  85   * @deprecated Deprecated by (@link Form::end_field())

  86   */
  87  function form_fieldend()
  88  {
  89      return "</div>\n</fieldset>\n\n";
  90  }
  91  
  92  /**

  93   * Start an info field.

  94   *

  95   * An info field is a fielset containing a label div and an info div.

  96   *

  97   * @deprecated Deprecated by (@link Form::info_field())

  98   */
  99  function form_infostart( $field_label )
 100  {
 101      return "<fieldset>\n".
 102                      '<div class="label">'.$field_label.":</div>\n".
 103                      '<div class="info">';
 104  }
 105  
 106  /**

 107   * End an info field.

 108   *

 109   * An info field is a fielset containing a label div and an info div.

 110   *

 111   * @deprecated Deprecated by (@link Form::info_field())

 112   */
 113  function form_infoend()
 114  {
 115      return "</div>\n</fieldset>\n\n";
 116  }
 117  
 118  
 119  /**

 120   * Builds a text (or password) input field.

 121   *

 122   * @deprecated Deprecated by (@link Form::text_input())

 123   *

 124   * @param string the name of the input field

 125   * @param string initial value

 126   * @param integer size of the input field

 127   * @param string label displayed in front of the field

 128   * @param string note displayed with field

 129   * @param integer max length of the value (if 0 field_size will be used!)

 130   * @param string the CSS class to use

 131   * @param string input type (only 'text' or 'password' makes sense)

 132   * @param boolean display (default) or return

 133   * @return mixed true (if output) or the generated HTML if not outputting

 134   */
 135  function form_text( $field_name, $field_value, $field_size, $field_label, $field_note = '',
 136                                          $field_maxlength = 0 , $field_class = '', $inputtype = 'text', $output = true  )
 137  {
 138      if( $field_maxlength == 0 )
 139          $field_maxlength = $field_size;
 140  
 141      // question: is it necessary to enclose each field in a fieldset.

 142      // fplanque> YES, for CSS

 143      // shouldn't there be a fieldset for a set of field (i.e. all fields

 144      // in the form)?

 145      // fplanque>> Create a new 'simple' layout if this is what you want

 146  
 147      $r = "<fieldset>\n"
 148              .'<div class="label"><label for="'.$field_name.'">'.$field_label.":</label></div>\n"
 149              .'<div class="input"><input type="'.$inputtype.'" name="'.$field_name
 150              .'" id="'.$field_name.'" size="'.$field_size.'" maxlength="'.$field_maxlength
 151              .'" value="'.format_to_output($field_value, 'formvalue').'"';
 152      if( !empty($field_class) )
 153      {
 154          $r .= ' class="'.$field_class.'"';
 155      }
 156      $r .= " />\n";
 157  
 158      if( !empty( $field_note ) )
 159      {
 160          $r .= '<span class="notes">'.$field_note.'</span>';
 161      }
 162  
 163      $r .= "</div>\n</fieldset>\n\n";
 164  
 165      if( $output )
 166      {
 167          echo $r;
 168          return true;
 169      }
 170      else
 171      {
 172          return $r;
 173      }
 174  }
 175  
 176  
 177  /**

 178   * form_text_tr(-)

 179   *

 180   * @deprecated Deprecated by (@link Form::text_input())

 181   */
 182  function form_text_tr( $field_name, $field_value, $field_size, $field_label, $field_note = '', $field_maxlength = 0 , $field_class = '' )
 183  {
 184      if( $field_maxlength == 0 )
 185          $field_maxlength = $field_size;
 186  
 187      echo '<tr>';
 188      echo '  <td align="right"><label for="', $field_name, '"><strong>', $field_label, ':</strong></label></td>';
 189      echo '  <td><input type="text" name="', $field_name, '" id="', $field_name, '" size="', $field_size, '" maxlength="', $field_maxlength, '" value="', format_to_output($field_value, 'formvalue'),'"';
 190      if( !empty($field_class) )
 191      {
 192          echo ' class="', $field_class,'"';
 193      }
 194      echo '/>';
 195      echo '  <small>', $field_note, '</small></td>';
 196      echo "</tr>\n\n";
 197  }
 198  
 199  
 200  /**

 201   * Builds a hidden field.

 202   *

 203   * @deprecated Deprecated by (@link Form::button_input())

 204   *

 205   * @param string name

 206   * @param string value

 207   * @return string

 208   */
 209  function form_hidden( $field_name, $field_value, $display = true )
 210  {
 211      $r = '<input type="hidden" name="'.$field_name
 212                  .'" value="'.format_to_output($field_value, 'formvalue').'" />'."\n";
 213      if( $display )
 214      {
 215          echo $r;
 216          return true;
 217      }
 218  
 219      return $r;
 220  }
 221  
 222  
 223  /**

 224   * Build a text area.

 225   *

 226   * @deprecated Deprecated by (@link Form::textarea_input())

 227   *

 228   * @param string

 229   * @param string

 230   * @param integer

 231   * @param string

 232   * @param string

 233   * @param integer

 234   * @param string

 235   */
 236  function form_textarea( $field_name, $field_value, $field_rows, $field_label,
 237                                                  $field_note = '', $field_cols = 50 , $field_class = '' )
 238  {
 239      global $rsc_url;
 240  
 241      echo '<fieldset>';
 242      echo '  <div class="label"><label for="', $field_name, '">', $field_label, ':</label></div>';
 243      echo '  <div class="input"><fieldset class="input"><img src="'.$rsc_url.'img/blank.gif" width="1" height="1" alt="" /><textarea name="', $field_name, '" id="', $field_name, '" rows="', $field_rows, '"  cols="', $field_cols, '"';
 244      if( !empty($field_class) )
 245      {
 246          echo ' class="', $field_class,'"';
 247      }
 248      echo '>'.$field_value.'</textarea></fieldset>';
 249      echo '  <span class="notes">', $field_note, '</span></div>';
 250      echo "</fieldset>\n\n";
 251  }
 252  
 253  
 254  /**

 255   * Display a select field and populate it with a callback function.

 256   *

 257   * @deprecated Deprecated by (@link Form::select_input())

 258   *

 259   * @param string field name

 260   * @param string default field value

 261   * @param callback callback function

 262   * @param string field label to be display before the field

 263   * @param string note to be displayed after the field

 264   * @param string CSS class for select

 265   */
 266  function form_select(
 267      $field_name,
 268      $field_value,
 269      $field_list_callback,
 270      $field_label,
 271      $field_note = '',
 272      $field_class = '' )
 273  {
 274      echo '<fieldset>';
 275      echo '  <div class="label"><label for="', $field_name, '">', $field_label, (($field_label != '') ? ':' : ''), '</label></div>';
 276      echo '  <div class="input"><select name="', $field_name, '" id="', $field_name, '"';
 277      if( !empty($field_class) )
 278      {
 279          echo ' class="', $field_class,'"';
 280      }
 281      echo '>';
 282  
 283      // call the callback function:

 284      $field_list_callback( $field_value );
 285  
 286      echo '  </select>';
 287      echo '  <span class="notes">', $field_note, '</span></div>';
 288      echo "</fieldset>\n\n";
 289  }
 290  
 291  
 292  /**

 293   * Display a select field and populate it with a cache object.

 294   *

 295   * @deprecated Deprecated by (@link Form::select_object())

 296   *

 297   * @param string field name

 298   * @param string default field value

 299   * @param DataObjectCache Cache containing values for list (get_option_list() gets called on it)

 300   * @param string field label to be display before the field

 301   * @param string note to be displayed after the field

 302   * @param boolean allow to select [none] in list

 303   * @param string CSS class for select

 304   */
 305  function form_select_object(
 306      $field_name,
 307      $field_value,
 308      & $field_object,
 309      $field_label,
 310      $field_note = '',
 311      $allow_none = false,
 312      $field_class = '' )
 313  {
 314      echo '<fieldset>';
 315      echo '  <div class="label"><label for="', $field_name, '">', $field_label, ':</label></div>';
 316      echo '  <div class="input"><select name="', $field_name, '" id="', $field_name, '"';
 317      if( !empty($field_class) )
 318      {
 319          echo ' class="'.$field_class.'"';
 320      }
 321      echo '>';
 322      echo $field_object->get_option_list( $field_value, $allow_none );
 323      echo '  </select>';
 324      echo '  <span class="notes">'.$field_note.'</span></div>';
 325      echo "</fieldset>\n\n";
 326  }
 327  
 328  
 329  /**

 330   * Generate set of radio options.

 331   *

 332   * @deprecated Deprecated by (@link Form::radio_input())

 333   *

 334   * @param string the name of the radio options

 335   * @param string the checked option

 336   * @param array of arrays the radio options (0: value, 1: label, 2: notes, 3: additional HTML [input field, ..], 4: attribs for <input tag> )

 337   * @param string label

 338   * @param boolean options on seperate lines (DIVs)

 339   * @param string notes

 340   */
 341  function form_radio(
 342      $field_name,
 343      $field_value,
 344      $field_options,
 345      $field_label,
 346      $field_lines = false,
 347      $field_notes = '' )
 348  {
 349      echo '<fieldset class="setting">';
 350      echo '  <div class="label">'.format_to_output($field_label).':</div>';
 351      echo '  <div class="input"><fieldset class="input">';
 352      foreach( $field_options as $loop_field_option )
 353      {
 354          if( $field_lines ) echo "<div>\n";
 355          echo '<label class="radiooption"><input type="radio" class="radio" name="'.$field_name.'" value="'.format_to_output( $loop_field_option[0], 'formvalue' ).'"';
 356          if( $field_value == $loop_field_option[0] )
 357          {
 358              echo ' checked="checked"';
 359          }
 360          if( !empty( $loop_field_option[4] ) )
 361              echo ' '.$loop_field_option[4];
 362          echo ' /> ', $loop_field_option[1], '</label>';
 363          if( !empty( $loop_field_option[2] ) )
 364          { // notes for radio option
 365              echo '<span class="notes">', $loop_field_option[2], '</span>';
 366          }
 367          if( !empty( $loop_field_option[3] ) )
 368          { // optional text for radio option (like additional fieldsets or input boxes)
 369              echo $loop_field_option[3];
 370          }
 371          if( $field_lines ) echo "</div>\n";
 372      }
 373      if( !empty( $field_notes ) )
 374      {
 375          echo '<div><span class="notes">'.$field_notes.'</span></div>';
 376      }
 377      echo '  </fieldset></div>';
 378      echo "</fieldset>\n\n";
 379  }
 380  
 381  
 382  /**

 383   * form_checkbox(-)

 384   *

 385   * @deprecated Deprecated by (@link Form::checkbox())

 386   *

 387   * @param string the name of the checkbox

 388   * @param boolean initial value

 389   * @param string label

 390   * @param string note

 391   * @param string CSS class

 392   * @param boolean to output (default)  or not

 393   * @return mixed true (if output) or the generated HTML if not outputting

 394   */
 395  function form_checkbox( $field_name, $field_value, $field_label, $field_note = '',
 396                                                  $field_class = '', $output = true )
 397  {
 398      $r = "<fieldset>\n"
 399              .'<div class="label"><label for="'.$field_name.'">'.$field_label.":</label></div>\n"
 400              .'<div class="input"><input type="checkbox" class="checkbox" name="'.$field_name.'" id="'
 401              .$field_name.'" value="1"';
 402      if( $field_value )
 403      {
 404          $r .= ' checked="checked"';
 405      }
 406      if( !empty($field_class) )
 407      {
 408          $r .= ' class="'.$field_class.'"';
 409      }
 410      $r .= " />\n"
 411                  .'<span class="notes">'.$field_note."</span></div>\n"
 412                  ."</fieldset>\n\n";
 413  
 414      if( $output )
 415      {
 416          echo $r;
 417          return true;
 418      }
 419      else
 420      {
 421          return $r;
 422      }
 423  }
 424  
 425  
 426  /**

 427   * form_checkbox_tr(-)

 428   *

 429   * @deprecated Deprecated by (@link Form::checkbox_input())

 430   */
 431  function form_checkbox_tr( $field_name, $field_value, $field_label, $field_note = '', $field_class = '' )
 432  {
 433      echo '<tr>';
 434      echo '  <td align="right"><label for="', $field_name, '"><strong>', $field_label, ':</label></strong></td>';
 435      echo '  <td><input type="checkbox" name="', $field_name, '" id="', $field_name, '" value="1"';
 436      if( $field_value )
 437      {
 438          echo ' checked="checked"';
 439      }
 440      if( !empty($field_class) )
 441      {
 442          echo ' class="', $field_class,'"';
 443      }
 444      echo ' />';
 445      echo '  <small class="notes">', $field_note, '</small></td>';
 446      echo "</tr>\n\n";
 447  }
 448  
 449  
 450  /**

 451   * form_info(-)

 452   *

 453   * @deprecated Deprecated by (@link Form::info_field())

 454   */
 455  function form_info( $field_label, $field_info, $field_note = '' )
 456  {
 457      echo '<fieldset>';
 458      echo '  <div class="label">', $field_label, ':</div>';
 459      echo '  <div class="info">', $field_info;
 460      if( !empty($field_note) )
 461      {
 462          echo '&nbsp; <small class="notes">', $field_note, '</small>';
 463      }
 464      echo '</div>';
 465      echo "</fieldset>\n\n";
 466  }
 467  
 468  
 469  /**

 470   * form_info_tr(-)

 471   *

 472   * @deprecated Deprecated by (@link Form::info_field())

 473   */
 474  function form_info_tr( $field_label, $field_info, $field_note = '' )
 475  {
 476      echo '<tr>';
 477      echo '  <td align="right"><strong>', $field_label, ':</strong></td>';
 478      echo '  <td>', $field_info;
 479  
 480      if( !empty($field_note) )    echo ' <td class="small">', $field_note, '</td>';
 481  
 482      echo "</td></tr>\n\n";
 483  }
 484  
 485  
 486  /**

 487   * Builds a form header and puts GET params of $action into hidden form inputs

 488   *

 489   * @deprecated Deprecated by (@link Form::begin_form())

 490   */
 491  function form_formstart( $action, $class = '', $name = '', $method = 'get', $id = '' )
 492  {
 493      if( $method == 'get' )
 494      {
 495          $action = explode( '?', $action );
 496          if( isset($action[1]) )
 497          { // we have GET params in $action
 498              $getparams = preg_split( '/&amp;|&/i', $action[1], -1, PREG_SPLIT_NO_EMPTY );
 499          }
 500          $action = $action[0];
 501      }
 502  
 503      echo '<form action="'.$action.'" method="'.$method.'"';
 504  
 505      // this is not xhtml strict, see: http://forums.b2evolution.net//viewtopic.php?t=8475

 506      // if( !empty($name) ) echo ' name="'.$name.'"';

 507      if( !empty($id) ) echo ' id="'.$id.'"';
 508      if( !empty($class) ) echo ' class="'.$class.'"';
 509  
 510      echo '>';
 511  
 512      if( isset($getparams) )
 513      { // These need to be wrapped in a div to validate xhtml strict
 514          echo '<div>';
 515          foreach( $getparams as $param)
 516          {
 517              $param = explode( '=', $param );
 518              if( isset($param[1]) )
 519              {
 520                  echo '<input type="hidden" name="'.$param[0].'" value="'.$param[1].'" />';
 521              }
 522          }
 523          // close the div

 524          echo '</div>';
 525      }
 526  }
 527  
 528  /**

 529   *

 530   * @deprecated Deprecated by (@link Form::end_form())

 531   */
 532  function form_submit( $submit_attribs = '' )
 533  {
 534      ?>
 535      <fieldset class="submit">
 536          <fieldset>
 537              <div class="input">
 538                  <input type="submit" name="submit" value="<?php echo T_('Save !') ?>" class="SaveButton" <?php echo $submit_attribs; ?> />
 539                  <input type="reset" value="<?php echo T_('Reset') ?>" class="ResetButton" />
 540              </div>
 541          </fieldset>
 542      </fieldset>
 543      <?php
 544  }
 545  
 546  /*

 547   * $Log: _form.funcs.php,v $

 548   * Revision 1.1  2007/06/25 10:59:02  fplanque

 549   * MODULES (refactored MVC)

 550   *

 551   * Revision 1.8  2007/04/26 00:11:07  fplanque

 552   * (c) 2007

 553   *

 554   * Revision 1.7  2006/11/24 18:27:27  blueyed

 555   * Fixed link to b2evo CVS browsing interface in file docblocks

 556   */
 557  ?>


Généré le : Thu Nov 29 23:58:50 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics