Update page from form submission

Hey there, I want to add a form to my website which takes an input, gets the page with the input as title and then updates its content with the submitted data.

the function looks as follows:

   $update = page(get('input'))->update([
        ...
    ]);

I also tried to get the page with filterBy. But I always get that error message:

Call to a member function update() on null

Does anyone have an idea for that problem?

tanks in advance!

What does get('input') give you? If that’s the title of the page, then you would have to try and find the page by title: $pages->findBy('title', get('input')) and before you call update() you have to check if the page exists.

Thank you, I will try that. get(‘input’) gives me a string

your solution solved it, thank you!!!

Make sure to sanitize/validate user input before you pass it to a method, in this example, passing a script to the page() helper probably won’t do any harm, but in other cases it might be really dangerous.