Closed (fixed)
Project:
Date
Version:
5.x-2.0-rc4
Component:
Date Popup
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
4 Aug 2008 at 00:26 UTC
Updated:
10 Sep 2008 at 05:23 UTC
This is date api _rc4. Drupal 5.8, PHP version 5.2.5.
The following module passes a date value when used with #type => date_text, but it returns null with #type => date_popup. I played around with the format strings and tried both examples in date_popup.module.
| Comment | File | Size | Author |
|---|---|---|---|
| sc_date_add.zip | 1.59 KB | alan426 |
Comments
Comment #1
alan426 commentedP.S. It works ok if you remove the #date_timezone element from the $form definition.
Comment #2
karens commentedPlease don't make me download and unzip a file to help you with this. This is probably not a bug since this works fine in the current code, it is probably a misunderstanding of how to use the API. If you post the text of the module code I may be able to scan through it and see what you're doing.
Comment #3
alan426 commentedSorry, I've been traveling. Here you go:
===========================
<?php
// $Id$
/**
* Small Claims Date Add
* Allows user input of a date to create morning and afternoon
* Small Claims Calendars in civicrm_event
*/
/**
* Implementation of hook_menu().
*/
function sc_date_add_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array(
'path' => 'sc_add',
'title' => t('Add Small Claims Calendar'),
'callback' => 'drupal_get_form',
'callback arguments' => array('sc_add_dateform'),
'access' => TRUE
);
}
return $items;
}
/**
* Defines the form.
*/
function sc_add_dateform() {
// Get date from user
$form = array();
// Creating the date/time element starts here
// Provide a default date in the format YYYY-MM-DD HH:MM:SS.
$date = '2008-12-31';
// Provide a format using regular PHP format parts (see documentation on php.net).
// If you're using a date_select, the format will control the order of the date parts in the selector,
// rearrange them any way you like. Parts left out of the format will not be displayed to the user.
$format = 'm/d/Y';
$form['sc_date'] = array(
'#type' => 'date_text', // types 'date_popup', 'date_select', 'date_text' and 'date_timezone' are supported. See .inc file.
'#title' => t('Select a date'),
'#default_value' => $date,
'#date_format' => $format,
'#date_label_position' => 'within', // See other available attributes and what they do in date_api_elements.inc
'#date_timezone' => 'America/Los Angeles', // Optional, if your date has a timezone other than the site timezone.
'#date_increment' => 15, // Optional, used by the date_select and date_popup elements to increment minutes and seconds.
'#date_year_range' => '-3:+3' // Optional, used to set the year range (back 3 years and forward 3 years is the default).
);
// the 'submit' button.
$form['submit'] = array('#type' => 'submit', '#value' => t('Save'));
return $form;
}
/**
* Handle post-validation form submission.
*/
function sc_add_dateform_submit($form_id, $form_values) {
$date = $form_values['sc_date'];
echo $date;
drupal_set_message(t('The date you selected was, %sc_date', array('%sc_date' => $date)));
}
Comment #4
karens commentedYour timezone name has a space in it, which is invalid. Use underscores instead of spaces. It should be 'America/Los_Angeles', not 'America/Los Angeles'.
Comment #5
alan426 commentedOops, that's obvious. Thanks Karen!
Comment #6
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.