Permalink needs to be unique error when editing
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 #168095
Sorry, 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 #168097
The 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 #168098
No, I’m not sure how to attach the slug/id to $slug.July 30, 2012 at 3:24 pm #168100
How 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 #168101
I’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 creation, the URL is automatically generated based on the event name.
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:
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.
You must be logged in to reply to this topic.