Jump to content

Empty a page field via frontend


verdeandrea
 Share

Recommended Posts

Hi guys,

i need to create or edit some pages via front-end.

The problem is I don't get how to empty a field for an existing page and dave a new value.

I'll try to be clear with this example:

the page has a field named "countries" - page fieldtype.

It has this value: [pageA, pageB]

When save this field like this via frontend

$page->countries = [pageC, pageD];

the new value of the field is [pageA, pageB, pageC, pageD] and not just [pageC, pageD].

So i need to empty the field before save the new value, or just the new value to overwrite the old one but i can't get how to do it.

Thanks!

Link to comment
Share on other sites

Values for page type fields that store multiple values are PageArrays. Since PageArray extends WireArray, you can use it's methods here -- such as removeAll().

Running $page->countries->removeAll() before adding new items should do the trick. It'll clear the PageArray and you can start from clean slate, so to speak. You should also take a look at other WireArray and PageArray methods, as those provide some nice ways to manage stored items etc.

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...