1

I am allowing users to pick a start date and time. From that start date and time, I would like to programatically set the end date and time to "start time + 2 hours".

The issues that I'm running into are:

  1. How do I collect an end date without showing the user the "end date" field?
  2. How do I automatically force the end date to be 2 hours later than the start date?
  • It's not clear from your question what part of Drupal you are using to create this form. Is this a webform? A node? Custom module? Something else? – Coleman Nov 13 '14 at 19:41
  • Sorry, I am just using the standard node creation form. – Ryan Nov 13 '14 at 21:39
  • One could ask why you'd bother storing an end-date to begin with if you know what it will always be. Regardless: Collect the end date as normal, then set #access => FALSE on the form item. That'll hide it from users. Use hook_entity_presave to manually set it's value to whatever you want. Done. – Letharion Nov 17 '14 at 9:15
  • Also, please don't answer questions about your question by further commenting. Answer them by updating the question. – Letharion Nov 17 '14 at 9:16

Your Answer

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

Browse other questions tagged or ask your own question.