Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Forms & Blueprints

Possible to get Date value in form field?

Started by James Olewiler 8 years ago · 1 replies · 1204 views
8 years ago

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:

YAML
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!

8 years ago

@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.

  1. Create new plugin
    BASH
    $ bin/plugin devtools new-plugin
    
  2. In 'user/plugins/my-plugin/my-plugin.php' I added:
    TXT
    public static function now()
    {
       return date('Y-m-d h:i:s', time());
    }
    
  3. In '/user/plugin/my-plugin/blueprints.yaml' I defined the field as:
    YAML
    hidden_date:
     type: hidden
     data-default@: '\Grav\Plugin\MyPluginPlugin::now'
    

    In the admin page of the plugin, Grav generated the following hidden field.

    TXT
    <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
last edited 07/21/18 by pamtbaau

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by Ton Haarmans, 5 years ago
13 1138 4 months ago
Forms & Blueprints · by Hugo Oliveira, 5 months ago
0 62 5 months ago
Forms & Blueprints · by Flachy Joe, 6 months ago
9 136 6 months ago
Forms & Blueprints · by Augustus, 7 months ago
7 110 7 months ago
Forms & Blueprints · by Julien, 7 months ago
10 130 7 months ago