Hi,

It has been a while since I used Drupal and I was trying to use something I did in the past. Which is adding a small piece of php code in a basic page.

I have a form that shows a date picker and I would like it to be pre-populated with today's date.

So I thought to use this format:

<input type="date" value="<?php echo date('Y-m-d');?>">

But when I do that the PHP code is stripped by CKEditor5

I have been reading into that and tried to add the php tag to the source editing field of the full html text format but that doesn't help.

Would be great if I could get some guidance on how to do this

Greetings,

Rob

Comments

robbnl’s picture

I found that I can use that small php code piece when I use the PHP filter in drupal 9. I can see why it has been removed from drupal as a security measure because users can execute php code. But I don't have users, it's just me maintaining a simple site.

I read that I have to create a module to execute such PHP code. But to me that sounds like overkill for something simple as this.

vm’s picture

the php filter module was removed from core and is in contrib as of Drupal 10 and can be found @ https://www.drupal.org/project/php

Not just a security measure but also a troubleshooting measure as embedded code can break a site and when it is tucked in the DB finding it can be a challenge

robbnl’s picture

Hi,

Thanks for the response. The php filter module is no longer supported with v10. I had installed it and then the checkbox to enable it remains grayed out and the accompanying text says that it can not be used with v10.

Greetings,

Rob

vm’s picture

https://www.drupal.org/project/php/issues/3363035 is a patch that can be used for D10.

robbnl’s picture

Hi, thanks for your reply, with that patch it will work with v10 but I don't think it is future proof to start building my site with a module that will no longer be maintained and where I would have to depend on a possible patch.

After some research I found that the Token and Token filter modules do exactly waht I need. In my input field I can use a token in the following format:

<input type="date" name="date" value="[current-date:custom:Y-m-d]">

And then I get the current date.

I have now deployed my site under development with v10 and this now all works as it was before in the pre v8 era but then with the new supported and maintained themes and modules.

chike’s picture

You can try the Twig filter module, https://www.drupal.org/project/filter_twig

Enable the module and add to a text format following instructions on the project page. Then write Twig, https://twig.symfony.com/doc/3.x/filters/date.html in CKEditor freely as you like.