Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

Conflict with updated Form plugin and Add Page By Form

form plugins

Solved by pamtbaau View solution

Started by DrPen 3 weeks ago · 2 replies · 274 views
3 weeks ago

Hello everyone.

Recently the updated Form plugin broke Add-Page-By Form, and it would not create any new pages from the front end. Add-Page-By Form is an old plugin that has worked on all previous versions with the form plugin that Ive used. As many here will know, Add-Page-By Form has not been updated for a long time but nevertheless always worked.

The error it made was Call to a member function toArray() on array

this error is listed in the release changelogs in Form version v9.1.12 as a bugfix, but even Form v9.1.11 did not work. The last Form version that does not break Add-Page-By Form is Form v9.1.10. I have tested previous versions to this and they all work to at least Form v8.2.1. I intend to test random Form versions that are much more recent to see if they work - eg Form v9.1.25, but do not expect them to work.

  • the recent updated Form plugin that broke Add-Page-By-Form is Form v9.1.35
  • the 'last' Form plugin that works is v9.1.10

NB I also use the Form plugin for logging into the front end. The updated Form plugin did not break this. I do not fully understand how grav forms work because its very complicated to a non grav dev. But I got these forms to work relatively easily and they have worked for at least 2 years.

Add-Page-By-Form

The yaml I use to create a new page from the front end

YAML
form:
    name: add_page.blogpost
    classes: add-page
    fields:
        -
            name: title
            label: title
            type: text
        -
            name: taxonomy.tag
            label: 'tags (comma sep)'
            type: text
#        -
#            name: featured
#            label: featured
#            type: text
        -
             name: starred
             label: 'starred'
             type: checkbox
             default: false
        -
            name: content
            label: 'content (editable)'
            type: textarea
            size: long
            classes: editor
        -
            name: honeypot
            type: honeypot
    buttons:
        -
            type: submit
            value: create
    process:
        -
            timestamp:
                name: timestamp
        -
            add_page: true
        -
            redirect: /notes
---

Maybe people will have ideas or even a simple tech solution to this. I think its safe to edit Add-Page-By-Form as it is no longer updated.

last edited 10/24/26 by DrPen
3 weeks ago Solution

In file 'add-page-by-form.php', change line 422 and remove ->toArray().

PHP
// Get all form field values
$form_data = $form->value()->toArray();

An array does not have a function toArray(). It already is... Hence the error: Call to a member function toArray() on array.

last edited 10/25/26 by pamtbaau
3 weeks ago

@pamtbaau thanks so much, this has done the trick straight away. Edited line 422, and re-enabled form v9.1.35 and a page is created with no errors.

PHP
// add-page-by-form.php line 422
// Get all form field values - edited to remove ->toArray()
$form_data = $form->value();

Very grateful you shared this, and it helps me going forward to understand a little more of the php structure in relation to errors. Sorry to be a bit slow on that.

Suggested topics

Topic Participants Replies Views Activity
Plugins · by renedebaaij, 4 weeks ago
1 255 3 weeks ago
Plugins · by Thomas, 4 weeks ago
1 271 3 weeks ago
Plugins · by complanar, 1 month ago
6 590 1 month ago
Plugins · by BenLaKnet, 1 month ago
1 491 1 month ago
Plugins · by complanar, 2 months ago
2 684 2 months ago