verdeandrea Posted April 29, 2014 Share Posted April 29, 2014 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 More sharing options...
teppo Posted April 30, 2014 Share Posted April 30, 2014 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. 2 Link to comment Share on other sites More sharing options...
verdeandrea Posted May 4, 2014 Author Share Posted May 4, 2014 Great! Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now