Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

get one date or timestamp from html_select_date

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks
View previous topic :: View next topic  
Author Message
burzum
Smarty n00b


Joined: 05 Feb 2007
Posts: 4

PostPosted: Wed Feb 07, 2007 2:32 am    Post subject: get one date or timestamp from html_select_date Reply with quote

Code:

   /*
    *    I use a method in my SQL-class $sql->update($table,$assocarray,$where) to
    *    automaticly escape the data from the assocarray and write the data of it
    *    into the databasefields according to the assocarray keys.
    *
    *    Now i had the problem to process the smarty html_date_select fields
    *    because it returns 3 fields or one htmlarray. I've choosen the array
    *    to automaticly process the 3 fields into a dateformat (YYYY-MM-DD or
    *    unixtimestamp) and one "field".
    *
    *    @param string $prefix
    *    @param string $mode
    *
   */
   function parseDateSelect($prefix,$mode = 'date')
   {
      foreach(array_keys($_POST) as $key)
      {
         // check for prefix and array if yes...
         if(is_array($_POST[$key]) AND strstr($key,$prefix))
         {
            // ...convert the array into YYYY-MM-DD...
            if($mode == 'date')
            {
               $date   = $_POST[$key]['Date_Year'].'-'.
                       $_POST[$key]['Date_Month'].'-'.
                       $_POST[$key]['Date_Day'];
            }
            // ...or into a unixtimestamp.
            if($mode == 'unix')
            {
               $date = mktime (0,0,0,$_POST[$key]['Date_Month'],
                                $_POST[$key]['Date_Day'],
                                $_POST[$key]['Date_Year']);
            }
            // Now strip the prefix from the key
            $newkey = substr($key,strlen($prefix));
            // and set the new key and it's data
            $_POST[$newkey] = $date;
            // remove the datearray from $_POST
            unset($_POST[$key]);
         }
      }
   }


Any further suggestions or better ideas?
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP