Hi,
Please note ...I am learning to program in Drupal/PHP....and have tried getting help from posts in the forum....not much luck...
I am exploring the use of the javascript popup calendar (jscalendar) in a custom node module. I am creating a very basic module to test this. Also, I've used the readme file provided by the author of jscalendar for help.
the main functions of the module is listed below.
here's a brief description
I am able to use the pop calendar attached to the field, fromdate to select a date. It is entered in the table, exam as : 2007-07-17 13:28:06.
fieldtype of fromdate in table exam is varchar2(20).
When I view the node, I see the value of fromdate.
When I go to edit the node, the text field fromdate in the form is blank. If I use this popup calendar in a CCK nodetype, the value does appear in the textfield when the node is viewed in edit mode.
I would like the value to appear in the textfield ,fromdate when the node (that is, from my custom module)is viewed in edit mode.
I suspect it is my exam_load that may be the problem....or do I have to use exam_prepare function to set the date display format. I've tried this..not getting it to work...I'm not understanding this properly.
Any ideas on what I am doing incorrectly or not doing at all....or need to do ?
I would appreciate any help please..thanks alot. Here's the code Ive been working with..
function exam_form(&$node) {
$form['exam_title'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#required' => TRUE,
'#default_value' => $node->exam_title,
'#weight' => -5,
'#description' => t('Name')
);
$form['examdate'] = array(
'#type' => 'textfield',
'#attributes' => array('class' => 'jscalendar'),
// Use only year, month, and day in textfield.
'#jscalendar_ifFormat' => '%Y-%m-%d %H:%M:%S',
// Don't show time.
'#jscalendar_showsTime' => 'true',
// Show 24-hour clock.
'#jscalendar_timeFormat' => '12',
);
return $form;
}
function exam_insert($node) {
db_query("INSERT INTO {exam} (nid, exam_title, examdate) VALUES (%d, '%s', '%s')", $node->nid, $node->exam_title, $node->examdate);
}
function exam_prepare(&$node) {
//not sure about this...think its wrong
$node->examdate = date('Y-m-d H:M:S', $node->examdate);
}
function exam_load($node) {
$t1 = db_fetch_object(db_query('SELECT exam_title, examdate FROM {exam} WHERE nid = %d', $node->nid));
return $t1;
}
function exam_update($node) {
db_query("UPDATE {exam} set exam_title='%s', examdate='%s' WHERE nid=%d", $node->exam_title, $node->examdate, $node->nid);
}
function exam_delete(&$node) {
db_query('DELETE FROM {exam} WHERE nid = %d', $node->nid);
}
Comments
Sorry about the double post...
I apologize for this double post..sorry
No Help Available ??? .....Again?
Has anyopne done this before? Doesn't seem to be that unique an activity....if you've used the javascript popup calendar in module development..... would really like to hear from you all. thanks
Missing #default_value for examdate
I see one problem for sure, in
$form['examdate'] = array(
'#type' => 'textfield',
'#attributes' => array('class' => 'jscalendar'),
// Use only year, month, and day in textfield.
'#jscalendar_ifFormat' => '%Y-%m-%d %H:%M:%S',
// Don't show time.
'#jscalendar_showsTime' => 'true',
// Show 24-hour clock.
'#jscalendar_timeFormat' => '12',
);
return $form;
}
you do not set the default value for examdate, so
as I a start I would change it to
$form['examdate'] = array(
'#type' => 'textfield',
'#default_value' => $node->examdate,
'#attributes' => array('class' => 'jscalendar'),
// Use only year, month, and day in textfield.
'#jscalendar_ifFormat' => '%Y-%m-%d %H:%M:%S',
// Don't show time.
'#jscalendar_showsTime' => 'true',
// Show 24-hour clock.
'#jscalendar_timeFormat' => '12',
);
return $form;
}
Thanks ..Problem Solved
I made the change you suggested, that is, to include '#default_value' => $node->examdate in the form item declaration (as you showed above).. It works fine....I'm very disappointed its so simple and I wasn't able to make the necessary correction...
Anyway, thanks again nevets for all your help.
A related issue I encountered
This is additional info I wish to provide as it may be relevant to someone who might perform these activities at some point in time.
I encountered another issue while trying to implement the javascript popup calendar in my custom node module. This related to the display of dates, that is how to create custom date display formats for use with
the javascript popup calendar.
nevets provided the necessary guidance and help on this issue as well. This is documented at
http://drupal.org/node/156833#comment-249130
Once again, thanks to nevets for his assistance when no-one seemed able to provide any help on these issues.
Date field with textfield attached?
Hello Dhar!
Am I to understand that what you are doing is making a custom module which allows you to make a CCK field with a date and a textfield attached to it? I am looking for exactly this for a CV setup I'm making, where users are supposed to submit school information and such. I've been trying to figure out how to do this, but I haven't managed yet... What I basically want is for instance something like this:
2000-2004 The School name
....where the numbers are two separate dates, and the School name is from an attached textfield.
If this resembles what you've been doing, I'd be grateful to see what you've accomplished, or even getting a copy of your module... The javascript calender aspect isn't important to me, just getting my hands on a module which does this would be excellent!!
Thanks,
joeboris