CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • can i set a custom date field to default to today's date?
Pages: [1]

Author Topic: can i set a custom date field to default to today's date?  (Read 2945 times)

josue

  • I post occasionally
  • **
  • Posts: 81
  • Karma: 7
    • PTP
  • CiviCRM version: 3.4.4, 4.1.1
  • CMS version: Drupal 6.24, Drupal 7.12
  • MySQL version: 5.0
  • PHP version: 5.2
can i set a custom date field to default to today's date?
February 26, 2009, 10:19:28 am
hey folks,

yes, i am working on a database today. hence all the questions. this one is also related to this dream variable i would like that would spit out today's date.

this group wants a custom date field to default to today's date. is there something i can put into the default field box that would give me that? if not, i did see kurund respond a while back to someone (http://forum.civicrm.org/index.php/topic,4850.0.html) with:

    If you are on CiviCRM v2.1, using buildForm() hook, you will be able to set defaults to custom data.

but have no idea how to implement that.

any feedback, ideas, documentation to read, etc. would be very welcome.

thanks!


Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: can i set a custom date field to default to today's date?
February 26, 2009, 10:59:06 am

this is on the list  for 2.3 and has come up often enough, that we definitely will implement in 2.3 :)

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: can i set a custom date field to default to today's date?
February 26, 2009, 11:16:57 am

did not really answer your question, but here are the steps:

1. Create and enable a new drupal module

2. Implement the hook_civicrm_buildForm in your module

3. for the appropriate variable do:

            $defaultDate = array( );
            CRM_Utils_Date::getAllDefaultValues( $defaultDate );
            $defaults['custom_XXX'] = $defaultDate;
            $form->setDefaults( $defaults );

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

jday

  • I post occasionally
  • **
  • Posts: 62
  • Karma: 6
  • CiviCRM version: 4.2
  • CMS version: 7.15
Re: can i set a custom date field to default to today's date?
February 27, 2009, 04:17:53 pm
sorry if this is a dumb question, for the "custom_XXX" part, would that be the column name where the value is stored?

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: can i set a custom date field to default to today's date?
February 27, 2009, 05:01:36 pm
Pretty sure custom_XXX is the form field name of the custom field which is constructed by appending the value of civicrm_custom_field.id to custom_

Doing a "view source" in your browser on a page which includes that field is the easiest way to figure out the value.
Protect your investment in CiviCRM by  becoming a Member!

jday

  • I post occasionally
  • **
  • Posts: 62
  • Karma: 6
  • CiviCRM version: 4.2
  • CMS version: 7.15
Re: can i set a custom date field to default to today's date?
February 27, 2009, 08:06:37 pm
I have three values:
custom_20[M],custom_20[d],custom_20[Y]

So I'm guessing I should delete that field and create a textfield version rather than a date field?

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: can i set a custom date field to default to today's date?
February 28, 2009, 07:44:11 am

The above snippet of code to set defaults, works for dates and we use it all over the place :)

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

jday

  • I post occasionally
  • **
  • Posts: 62
  • Karma: 6
  • CiviCRM version: 4.2
  • CMS version: 7.15
Re: can i set a custom date field to default to today's date?
February 28, 2009, 10:51:23 pm
will it work as a theme hook? my 'custum_20 is a date field in a civicrm profile, included in the user register form, so far I can't get it to work

Code: [Select]
function garland_civicrm_buildForm(&$form) {
   switch ($hook) {
    case 'user_register':
$defaultDate = array( );
        CRM_Utils_Date::getAllDefaultValues( $defaultDate );
        $defaults['custom_20'] = $defaultDate;
        $form->setDefaults( $defaults );
}
}

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: can i set a custom date field to default to today's date?
March 01, 2009, 07:05:44 am

i dont think a module hook is the same as a theme hook. u'll need to implement it as a module hook

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

jday

  • I post occasionally
  • **
  • Posts: 62
  • Karma: 6
  • CiviCRM version: 4.2
  • CMS version: 7.15
Re: can i set a custom date field to default to today's date?
March 02, 2009, 11:23:39 am
ok I built a custom module called "jdmod"

the only thing I could find on civicrm_buildForm in the wiki was this: hook_civicrm_buildForm( $formName, &$form )

Is $formName the same as form id? I have a profile set up for volunteer information and I've got the profile (id_4...is that the $formName?) included in the user registration page, when someone signs up for the volunteer group I want the date to be recorded along with their other info. I can't seem to find the right syntax, 'custom_20' is a profile date field...

<code>
function jdmod_civicrm_buildForm($formName, &$form) {
   if ($formName == 'id_4' || $formName == 'user_register') {
   $defaultDate = array( );
    CRM_Utils_Date::getAllDefaultValues( $defaultDate );
    $defaults['custom_20'] = $defaultDate;
    $form->setDefaults( $defaults );
   }
}

function user_register_civicrm_buildForm($formName, &$form) {
   $defaultDate = array( );
    CRM_Utils_Date::getAllDefaultValues( $defaultDate );
    $defaults['custom_20'] = $defaultDate;
    $form->setDefaults( $defaults );
}
</code>


Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: can i set a custom date field to default to today's date?
March 02, 2009, 02:43:49 pm

the quickest way to make progress on this is to add some debug statements at the beginning of the function:

Code: [Select]
function jdmod_civicrm_buildForm($formName, &$form) {
CRM_Core_Error::debug( $formName );
CRM_Core_Error::debug( $form );
exit( );

this should give u an idea of what the values are for cases u r interested in. in your case formName will be something like: CRM_Profile_Form_Edit ...

lobo

A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

jday

  • I post occasionally
  • **
  • Posts: 62
  • Karma: 6
  • CiviCRM version: 4.2
  • CMS version: 7.15
Re: can i set a custom date field to default to today's date?
March 02, 2009, 06:54:55 pm
Sweet! that did the trick, Thanks Lobo!!

jbertolacci

  • I post occasionally
  • **
  • Posts: 54
  • Karma: 1
Re: can i set a custom date field to default to today's date?
September 02, 2009, 08:57:49 am
Is there an issue tracker ticket open for this already or an update about the whether this improvement made it into 3.0beta1?

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: can i set a custom date field to default to today's date?
September 02, 2009, 02:06:58 pm

you will need to do this via a hook (its quite easy)

if you want to implement this in core, please submit a patch (and/or sponsor a developer to do the same). Its not a trivial patch, but not too complex either

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • can i set a custom date field to default to today's date?

This forum was archived on 2017-11-26.