Home » Topics » Pods 1.x » Permalink needs to be unique error when editing
Permalink needs to be unique error when editing
This topic contains 7 replies, has 2 voices, and was last updated by PG Lewis 9 months, 3 weeks ago.
-
AuthorPosts
-
July 28, 2012 at 8:09 am #168092
Hello, I’m trying to create a public form that lets users edit pods they’ve already created. However, when they submit the form, I’m always getting a “Permalink needs to be unique” error. I mean, obviously the permalink is going to be the same, it’s the same pod…
I think the problem is the format of my code. How do I call the previous pod’s slug or ID?
July 29, 2012 at 1:29 pm #168093“[...] obviously the permalink is going to be the same, it’s the same pod [...]” “[...] How do I call the previous pod’s slug or ID?”
I think you’re using “pod” to mean “a record” or “pod item” here. Generally “pod” refers to your custom type in general, the container. If not, then I’m completely confused.
Anyway, the docs for Column Types say a permalink column must be unique, and that’s the column type for the built-in slug field. So, each item you save has to have a unique slug. It sound like you’re trying to save an item with a slug value you’ve used on another existing item, but you haven’t said how you’re building your form and how you are saving the data… there are a few ways you could be going about it.
July 29, 2012 at 2:17 pm #168095Sorry, you’re right. “Pod item” is the correct term.
I’m trying to use publicForm to edit existing pods, but instead of the form editing a pod item, it creates a new one. This is where I’m lost:
$pods = new Pod(‘events’, $slug);
The slug is the value of an html input field. How do I go about transferring that field value into the publicForm function? I’ve tried things like “document.getElementById(‘pods_slug’).value”, where pods_slug is the input form that has the slug. But no results.
July 29, 2012 at 2:29 pm #168097The first two examples in the publicForm docs show how to set things up to either add a new item or to edit an existing one. You need to know whether you’re adding or editing at the time you call publicForm(), and if you’re editing you include either the slug or the id of the existing item you want to edit.
That appears to be the syntax you’re using: $pods = new Pod(‘events’, $slug); Are you certain $slug is holding the value you think it is?
July 29, 2012 at 2:53 pm #168098No, I’m not sure how to attach the slug/id to $slug.
July 30, 2012 at 3:24 pm #168100How are you integrating the public form with your theme template, including any Pods pages, templates or other bits involved? How does a user add a record? How do they edit an existing one? A URL to show what you have might also help, if available.
Pods is so flexible, there are many ways you could be doing things. The details for grabbing the slug for existing records will depend on how you’re going about it. It’s going to be an easy fix, it’s just getting the right incantation in there.
July 30, 2012 at 3:39 pm #168101I’d show you the page but it’s on a local server.
I’m using the Events Manager plugin that allows users to create and edit events. The EM plugin uses a regular form that saves event data to the database. Now, I’ve tried to integrate Pods to include some other features.
On one page, all the event gets saved normally (not as a pod item), and on the next page, all the data that the user had inputted gets automatically saved as a pod item in the “events” pod. So far, creating new events(pod items) works fine. It’s probably not the most elegant solution, but I have little coding knowledge so I just use hidden input fields and javascript to transfer the data from the previous page into the pod input fields, and then automatically submit the hidden pods form when the page loads.
On creation, the URL is automatically generated based on the event name.
Anyway, when a user is editing a previous event, I can assign the existing URL to a javascript variable. My issue is getting it in the right format in the publicForm function. Even simply copy-pasting the URL manually in the function doesn’t help.
Thanks so much for your help, btw!
July 30, 2012 at 4:02 pm #168102“On creation, the URL is automatically generated based on the event name”
If your URL is something like:
mysite.com/events/edit/pod_event_slug_name/
where the Pod item’s slug as the last part of the URL when editing an existing record, then getting a sanitized and ready to use slug name is as easy as putting this in your PHP code before your call to publicForm:
$slug = pods_url_variable(-1);
That function will take care of the work of extracting the slug name from the end of the URL and store it in the variable $slug. With a correct value in $slug your call to publicForm should work correctly. If your URL structure is different then that code bit may have to be adjusted a little.
-
AuthorPosts
You must be logged in to reply to this topic.