Edit form
Created 6 years ago by pdring

Hi,

Having created a stream, I can both display the data and add to it using a form generated through {{ form('flux', 'cities')|raw }}. However I'd also like to be able to edit the data for each entry on the frontend. Can this be done in a similar way? I'd simply need to know which ID to edit and that I could pass from the URL, ex. edit/5. It would also be useful to restrict editing to the creator of the original entry.

Thanks.

ryanthompson  —  6 years ago

You sure can - just use the entry option:

{{ form('flux', 'cities').entry(id|entry)|raw }}

This effectively runs setEntry() on the builder. If the id|entry evaluates to null it will be considered a creating form! So you don't need any logic switching on the front end for creating / editing using the same view if you don't want.

pdring  —  6 years ago

Spectacular!

If I use {{ form('flux', 'cities').entry(1)|raw }}, the entry displays perfectly and it updates without a problem.

Just one question: If I use {{ form('flux', 'cities').entry(1|entry)|raw }}, I get an error concerning the "entry" filter. What does this filter do?

Is there a way to restrict editing so that only the creator can update an entry?

Thanks again!

ryanthompson  —  6 years ago

Sorry - I meant to illustrate that you can use the entry object as well as it's ID there.