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

Get form data select input and add it to page frontmatter

Solved by Ron Wardenier View solution

Started by mikael 9 years ago · 3 replies · 1451 views
9 years ago

Hey:)

I am using Add page by form plugin for users to add custom content to a site.

Now I am working to add taxonomy to the added page frontmatter by being able to select a category from a select field.

So I know some basics of PHP, but only how the logic works, not really writing or having an idea of what it should look like at the end... So I really need some help to figure out this.
What I found that is the most promising so far is in Add page by form PHP on Github line 302

I guess this needs to contain a function to get the select field data and as it's there print the result to page frontmatter.

Thank you for any help!

9 years ago

So I have gotten a bit further... I have no idea how I got this far, how did $result = $form->value()->toArray(); know I wanted to get the selected option from this form?:

YAML
-
    name: taxonomy
    type: select
    size: long
    classes: fancy
    label: Category
    options:
        project: Project
        value2: Test
        value3: test2

From Add page to from PHP

PHP
$result = $form->value()->toArray();
$page_frontmatter['taxonomy'] = $result;

which becomes in frontmatter

taxonomy: project

and I try to make it like this:

YAML
taxonomy:
    category:
        - Projects
9 years ago Solution

I hadn't noticed this post before. Recently there was another request for support of taxonomy types, see Added easy category/tag support.

If you want you are welcome to test the 2.1.0 version of the plugin in the support-taxonomy feature branch.
The Add Blog Post example configuration in the README file contains an example of a simple text field.

There still is an issue with saving new taxonomy types to the site.yaml configuration file. Help with that add-page-by-form.php#L502 is very much appreciated.

👍 1
9 years ago

Thanks! I will check it out more. Although I decided for now that it is easier to create separate forms so I can add the different post to different sections of the site.

I will for sure simplify this method when I get further in the project, and then I will need to use every function this plugin has to offer!

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by Ton Haarmans, 5 years ago
13 1136 4 months ago
Forms & Blueprints · by Hugo Oliveira, 5 months ago
0 61 5 months ago
Forms & Blueprints · by Flachy Joe, 6 months ago
9 134 6 months ago
Forms & Blueprints · by Augustus, 7 months ago
7 110 7 months ago
Forms & Blueprints · by Julien, 7 months ago
10 129 7 months ago