Welcome Guest, Not a member yet? Register   Sign In
User inserting date time
#1

[eluser]Unknown[/eluser]
How can I let the user input full date and time information and then store it into a DATETIME field in my database. Do I have to create a full set of drop down menus for each item (year, month, hour, etc). I am familiar with Ruby on Rails which did this automatically.
#2

[eluser]markup2go[/eluser]
Personally I would use a single text input for the date, and dropdowns for the time; validate formats and date with a custom callback and run it against checkdate(). You can also use something like the jQuery UI for a nifty date picker to make it easier on the user to select a date.

Heres a hint at how I create the dropdowns in my view:

Code:
foreach(range(1,12) as $hour){
    if(strlen($hour) == 1){
        $hour = '0'.$hour;
    }
    echo '<option value="'.$hour.'" '.$this->validation->set_select('end_time_hour', $hour, FALSE).'>'.$hour.'</option>';
            }
#3

[eluser]bretticus[/eluser]
[quote author="Cheecho Mestanza" date="1255736853"]How can I let the user input full date and time information and then store it into a DATETIME field in my database. Do I have to create a full set of drop down menus for each item (year, month, hour, etc). I am familiar with Ruby on Rails which did this automatically.[/quote]

Codeigniter tries not to be too specific on functional controls. It's difficult to anticipate every configuration of a date + time control on a webpage, for example. In other words, you get functions (helpers) and classes (libraries) for dealing with basic html form controls but not bloated library that anticipates every control combination. Most CI users appreciate it's brevity and simplicity. In cases like this, I usually write my own tailored helper/lib and reuse it.

strtotime() is a useful PHP function for sticking combinations of date inputs together to make a date type (unix timestamp) and also for checking validity. From there, you could use something similar to the output of date('Y-m-d h:iConfused', $timestamp) before sending it to the database.

Good luck!




Theme © iAndrew 2016 - Forum software by © MyBB