Show
Ignore:
Timestamp:
11/17/04 17:22:16 (4 years ago)
Author:
argh
Message:

Updated to work with the new version

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/examples/example_element_date.php

    r151 r176  
    3232    require_once $neededFiles['patErrorManager']; 
    3333 
    34     // element definitions for this example 
    35     $elementsDefinition = array( 
    36         'xmess' => array( 
    37             'type' => 'Date', 
    38             'attributes' => array( 
    39                 'required'      =>  'yes', 
    40                 'display'       =>  'yes', 
    41                 'edit'          =>  'yes', 
    42                 'label'         =>  'X-Mess eve', 
    43                 'title'         =>  'X-Mess', 
    44                 'description'   =>  'Tell me when you celebrate x-mess.', 
    45                 'dateformat'    =>  'd.F.Y H:i:s', 
    46                 'presets'       =>  'no',           // use select boxes? yes|no 
    47                 'default'       =>  time(),         // timestamp or strtotime-compatible string 
    48                 'min'           =>  '-1 month',     // timestamp or strtotime-compatible string 
    49                 'max'           =>  '+1 month',     // timestamp or strtotime-compatible string 
    50                 //'returnformat'    =>  'timestamp' 
    51             ), 
    52         ), 
    53     ); 
    54      
    5534   /** 
    5635    * Attribute notes: 
     
    6847    *   timestamps directly when possible. 
    6948    * 
    70     * - the min and max attributes have to be set when setting 
    71     *   the presets attribute to yes, so the select boxes can 
    72     *   be filled with the right values. 
    73     *  
    7449    * - the returnformat attribute can be used to select the kind 
    7550    *   of value the date element will return. Possible values are  
    76     *   [datestring], [timestamp]. Default: [datestring] 
    77     * 
    78     *   Note also that some date format tokens like F are  
    79     *   automatically converted to a number representing the user 
    80     *   choice, e.g. 12 January 1994 is returned as 12 01 1994. 
     51    *   [isodate], [timestamp]. Default: [isodate] 
    8152    */ 
    82      
     53    $elementsDefinition = array( 
     54        'xmess' => array( 
     55            'type' => 'Date', 
     56            'attributes' => array( 
     57                //'required'        =>  'yes', 
     58                'display'       =>  'yes', 
     59                'edit'          =>  'yes', 
     60                'label'         =>  'X-Mess eve', 
     61                'title'         =>  'X-Mess', 
     62                'description'   =>  'Tell me when you celebrate x-mess.', 
     63                'dateformat'    =>  'Y.m.d. H:i:s', 
     64                'presets'       =>  'no',           // use select boxes? yes|no 
     65                'default'       =>  time(),         // timestamp, ISO 8601 date or strtotime-compatible string 
     66                'min'           =>  '-1 year',      // timestamp, ISO 8601 date or strtotime-compatible string 
     67                'max'           =>  '+10 years',    // timestamp, ISO 8601 date or strtotime-compatible string 
     68                //'returnformat'    =>  'timestamp' // 'timestamp' or 'isodate' default: 'isodate' => ISO 8601 date 
     69            ), 
     70        ), 
     71    ); 
    8372     
    8473    // create the form 
    8574    $form   =&  patForms::createForm( $elementsDefinition, array( 'name' => 'myForm' ) ); 
     75     
     76    // get the element to have some additonal fun with it 
     77    $el =& $form->getElementByName( 'xmess' ); 
     78     
     79    // If you want to retrieve the date in the date format you specified, 
     80    // you can use the following method: 
     81    //echo 'Formatted date: '.$el->getFormattedDate().'<p/>'; 
     82 
     83    // When using the set methods for the default, max and min dates, 
     84    // you can also use a PEAR::Date object as parameter. 
     85    //$el->setMax( new Date( strtotime( '+10 years' ) ) ); 
     86     
     87    // If you can't remember what the ISO date format is, simply use the 
     88    // provided method, getISOFormat() to get a format string for use with 
     89    // PHP's date() function. 
     90    //echo 'ISO date: '.date( $el->getISOFormat(), time() ); 
     91 
    8692     
    8793    // create the needed renderer 
     
    94100    $form->setAutoValidate( 'save' ); 
    95101 
    96     $el =&  $form->getElementByName( 'xmess' ); 
    97  
    98102    // serialize the elements 
    99103    $elements   =   $form->renderForm(); 
    100      
    101      
     104 
    102105    // ERROR DISPLAY ------------------------------------------------------ 
    103106    // ask the form if it has been submitted and display errors. For 
     
    109112        displayErrors( $form ); // see patExampleGen/customFunctions.php 
    110113    } 
    111  
     114     
    112115    // DISPLAY FORM ------------------------------------------------------ 
    113116    displayForm( $form, $elements ); // see patExampleGen/customFunctions.php