Get form data select input and add it to page frontmatter

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!

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?:

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

From Add page to from PHP

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

which becomes in frontmatter

taxonomy: project

and I try to make it like this:

taxonomy:
    category:
        - Projects

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 Like

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!