0

I have an webform with e-mails adresses that I want to send notifications to.

I want to make the title of the e-mail as e.g. "new message 2017-03-20".

I have tried with pattern suggested under another field (e-mail body):

new message %date

But it output the formatted date:

new message sunday, march 25, 2017 - 17:54

Is there a way to put here date in yyyy-mm-dd format without chaning the global date formatting on the website?

I also tried to add something like the pattern that is not listed under field:

new message [entity-fetched:field_event_date]

but it does not get replaced at all (I get message with that literal title):

new message [entity-fetched:field_event_date]
3
+50

Place this code in a custom module:

     /* first add a custom date field (mydate), you have to set it's value with rules */
  /* change all capital letters with proper names (in lower case) */
  function YOURMODULE_preprocess_node(&$vars) {
$vars['MYDATE'] = 
t('!datetime', 
  array('!datetime' => format_date($vars['node']->MYDATE, 
    'custom', 'M/d/Y, h:i a')));
}
  /* hide custom field to all users but admin */
function YOURMODULE_form_alter(&$form, &$form_state, $form_id) {
  global $user;
  $uuid = $user->uid;
  /*  check that user is NOT admin (No1) */
    if ($uuid !='1') {
        /* if is user profile form use: if ($form_id == 'user_profile_form')*/
      if ($form_id == 'YOUR_FORM_ID') {
      //dsm($form);
        hide($form['field_MYDATE']);
       }
 }

for a diferent format look at: http://php.net/manual/es/function.date.php

having date format correct, go agian and do:

new message %mydate
  • Thank you. One question: wouldn't it affect date format everywhere? I just want to set my custom format in message title (as is kind of serial number there) and not to change the format in mail body (if date is placed there too). Can it be distinguished inside HOOK_preprocess_webform somehow? – PolGraphic Apr 2 '17 at 16:59
  • 1
    HOOK_preprocess_webform only affects webform, if you do HOOK_preproccess_node it will affect all nodes, HOOK_preproccess_page will affect all pages, etc. you may have to try several functions like HOOK_preprocces_webform listed on second link to see wich one does what you want, – pinueve Apr 2 '17 at 17:04
  • 2
    you may need another date field, a hidden one, set same value with rules, format your custom field to fit you needs, original date field live it as it is. With this solution now you may use hook_preproccess_node on custom field and nothing will be changed, achiveing what you need. – pinueve Apr 3 '17 at 3:49
  • 2
    done, i added a function to hide custom date field to all users but admin, sorry for indentation, i could not make look nice, thanks for flagging my answer. – pinueve Apr 4 '17 at 18:45
  • 2
    i don't know why but i had to use code in this site, hope help others: if ($form_id == 'user_profile_form' OR $form_id == 'user_register_form') – pinueve Jun 11 '17 at 0:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.