Skip to content
World Wide Web Server edited this page Jul 4, 2012 · 34 revisions

Category:Library Category:Library::Date Category:Library::Form

FormDate is a class that creates select and option tags for date and time elements. It relies on the form helpers form_dropdown function. The [url=http://www.codeigniter.com/forums/viewthread/823/]forum thread[/url] were it all started.

[h3]Installation[/h3]

• Code Igniter version 1.5 or newer required. • [url=http://lab.rotsen.be/php/ci/formdate015.php.zip]Download & unzip formdate[/url]. • Put the formdate.php in your apps libraries folder. Create a libraries folder if it doesn’t exist.

[h3]Example[/h3]

Load and instanciate in controller [code]$this->load->library('formdate'); $formdate = new FormDate();[/code]

Set options [code]$formdate->setLocale('nl_BE'); $formdate->year['start'] = 1950; $formdate->year['end'] = 2006; $formdate->month['values'] = 'numbers';[/code]

Make formdate available in the view [code]$data['formdate'] = $formdate; $this->load->view('index', $data);[/code]

Display in view [code] <form> Name <input type="text" />

Day of Birth <?=$formdate->selectDay()?>
<?=$formdate->selectMonth()?>
<?=$formdate->selectYear()?>

<input type='button' /> </form> [/code]

[h3]Date Validation[/h3]

Date validations are easy to do with php's built in [url=http://be2.php.net/checkdate/]checkdate()[/url]. Put this function in a validation callback, feed it with the month, day and year from your POST array and it will return bool true if valid.

[code] function valid_date() { if (!checkdate($this->input->post('month'), $this->input->post('day'), $this->input->post('year'))) { $this->validation->set_message('valid_date', 'The %s field is invalid.'); return FALSE; } } [/code]

[h3]Release History[/h3]

Version 0.10 (14/06/2006)

• Initial test release

Version 0.11 (17/06/2006)

• Added config prefix

Version 0.12 (26/10/2006)

• Fixed hour, minute and second selection bugs (reported by Maciej Kus) • Converted to a library since scripts are deprecated since CI 1.4.

Version 0.13 (03/04/2007)

• Added day argument value of 1 to mktime() function in selectMonth() method. This fixes wrong double month option elements. • Added config option to display blank value for day, month and year select elements.

Version 0.15 (04/04/2007)

• Blank value is always first element in dropdown list. • Auto select blank element instead of current date when blank option setted. • Added blank value for hour, minute, second and meridian • phpDocumentor style comments • Deprecated init file.

Clone this wiki locally