I’m trying to submit a field in my form that includes today’s date, but get errors (obviously) when trying to do something like this:
name: hidden_date
type: hidden
default: {{ now }}
What allows the “process” part of the form plugin to read values like from: “{{ form.value.email }}” but trying similar throws big no-no’s? Thanks!
@thejame Have a look at Using Function Calls (data-*@)
Below is a working example.
I have done the following to get ‘now’ as default value in the Admin page of my plugin.
- Create new plugin
$ bin/plugin devtools new-plugin
- In ‘user/plugins/my-plugin/my-plugin.php’ I added:
public static function now()
{
return date('Y-m-d h:i:s', time());
}
- In ‘/user/plugin/my-plugin/blueprints.yaml’ I defined the field as:
hidden_date:
type: hidden
data-default@: '\Grav\Plugin\MyPluginPlugin::now'
In the admin page of the plugin, Grav generated the following hidden field.
<input data-grav-field="hidden" data-grav-disabled="false" type="hidden" class="input"
name="data[hidden_date]" value="2018-07-21 08:36:37">
1 Like