set default time in date field

cassembers

New Member
I have no idea if this is possible or not (I hope so).. but I have a date field. The user in the form is to specify a start date. The format is Y-m-d H:i:s .... can I set the time to auto populate 01:00:00 instead of 00:00:00??
I hope that makes sense.
thanks :)
cass
 
bump...

also set default date in date field-ie today's date automatically inserted into database.

We had it working in 1.0.3 but does not work in 1.0.4
 
Do you want to just set the date when the form is first filled in, or when it is edited as well?

If you just want to default to the current date / time when the form is created, you should be able to use an eval'ed element default something like:

return date('Y:m:d h:i:s');

Although you may have to match the date format string above with whatever you have set the format for the date element. For ingo on formatting date strings, see http://www.php.net/date.

If you want to set a hidden timestamp whenever the form is edited, you'll need to use a 'simple eval' form processing script, which sets the aData['table_name___element_name'] array value to whatever flavor of date() or UNIX style timestamp you want to use. So on the Form admin page (rather than the element page), select the "As soon as form submitted (simple eval)" option for script processing, and in the PHP box put something like:

$aData[jos_fabrik_formdata_3___edit_date] = date('Y:m:d h:i:s');

... which will set a date in standard MySQL date format, if you are using a Date element. Or you could just use a text/number element, and use timestamp() instead.

-- hugh
 
Hugh,
my problem is that.. the user is selecting the date from a calendar to input into the date field (it can't be hidden).. When they input it, it defaults the time to 00:00:00... I need it to default to 00:01:00.
Is this still possible with the code you mentioned above? I've tried editing it a bit to add in the time.. but it's still set to 00:00:00 when I enter a new item.
Please let me know..
thanks for your time on this!
 
Thanks for reminding me.

Short of adding a new option to default the time part of the date field, I don't see any built in way of doing this.

The only way I can suggest to work round this is to use a form submit script (simple eval, before form is processed) which uses preg_replace() to change '00:00:00' to '00:01:00' in $aData['your_element-name'].

-- hugh
 
Hmm.. Well, I have my client manually changing this (which forces him to check on things, which is probably a good thing)... so I'll leave it be for now. If he complains I'll look back into it more.. hahah ;)
Thanks again Hugh.
Cass
 
Really, the form script would literally be 2 lines. If you tell me the element name you need set, I'll write it for ya.

-- hugh
 
Hi Hugh,

I'd like this code if at all possible as I need to set the default time to anything after midday - 12:00:00.

I have to admit to just really scratching around the edges of PHP and so can customise and reuse, but not write from scratch!

Many thanks,

Jim
 
Not quite sure what you mean by "set the default time to anything after midday - 12:00:00".

Pliz to be explaining.

-- hugh
 
Hi Hugh,

Sorry about that it was a long day and I was a bit more dozy than I realised!

In summary I am using the the date element type and want it to enter the date selected with the time part set to '12:00:00' instead of '00:00:00'

I am storing the result in an element called date1

I think I need the same sort of script you were suggesting to Cass.

Thanks again

Jim
 
If your table is (for example) jos_fabrik_formdata_42, it would look like this:

$aData['jos_fabrik_formdata_42___date1'] = preg_replace('#00:00:00#','12:00:00',$aData['jos_fabrik_formdata_42___date1']);

BTW, that's three underscores between the table and element name.

Enter this as the PHP code on the Form admin page, with the script dropdown set to "As soon as form submitted (simple eval)".

If you are unsure of the jos_fabrik_formdata_42 part, just view the source of your form page, it should be fairly obvious what to use from the structure of your forms / elements.

-- hugh
 
Thanks Hugh,

The code works brilliantly. However the showcalendar button is returning Y-m-d as you can see from the excerpt of page source below:

<input type="reset" class="button" value="..." onclick="return showCalendar('jos_fabrik_formdata_3___date1', 'Y-m-d');" />

Therefore the script has nothing to match and replace as it is looking for yyyy-mm-dd hh:mm:ss and the calendar is only returning yyyy-mm-dd.

I have scoured my joomla install, but can not find where this is specified.

Any ideas?

Many thanks,

Jim
 
Oh, I hate the calendar widget. RIght now we use the built in J! one, which seems to cause us nothing but problems. Might be time to find some other open source calendar widget ...

I'll try and find some time to address your problem today.

-- hugh
 
Hi Hugh,

Previously I had attempted using Facile Forms, but abandoned it due to the way it stored the data.

However they used the jscalendar-1.0 included with Joomla which was more configurable:

Before Form
Code:
// include the javascript functions for dates
echo ('
 <script language="javascript" src="{mossite}/includes/js/mambojavascript.js" type="text/javascript"></script>
 <script type="text/javascript" src="{mossite}/includes/js/jscalendar-1.0/calendar_stripped.js"></script>
 <script type="text/javascript" src="{mossite}/includes/js/jscalendar-1.0/calendar-setup_stripped.js"></script>
 <script type="text/javascript" src="{mossite}/includes/js/jscalendar-1.0/lang/calendar-en.js"></script>
 <link rel="stylesheet" type="text/css" media="all" href="{mossite}/includes/js/jscalendar-1.0/calendar-system.css">
');

After form

Code:
// include to configure calendar behaviour
echo ('
 <script type="text/javascript">
  Calendar.setup(
   {
    inputField : "ff_elem244",  // ID of the input field
    ifFormat  : "%A, %d %B, %Y", // the date format
    button   : "ff_elem245",  // ID of the button
    singleClick : true,      // close popup on single click
    firstDay  : 1,        // Monday as first day of the week
    range    : [2005,2020]   // min and max years allowed
   }
  );
  Calendar.setup(
   {
    inputField : "ff_elem241",  // ID of the input field
    ifFormat  : "%A, %d %B, %Y", // the date format
    button   : "ff_elem242",  // ID of the button
    singleClick : true,      // close popup on single click
    firstDay  : 1,        // Monday as first day of the week
    range    : [2005,2020]   // min and max years allowed
   }
  );
 </script>
');

Hope this makes sense!

Jim
 
One more thing,

Code for the button:

Code:
js onclick:

// When button clicked, call the javascript function to show the calendar
// and pass the value back to the input text field. 
// NB: the value "StartDate" below must match the input text field name

function ff_SelectDate2_action(element, action)
{
  switch (action) {
    case 'click':
      return showCalendar(ff_getElementByName('EndDate').id, 'l, d F, Y');
      break;
    default:;
  } // switch
} // ff_SelectDate2_action
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top