ZionBludd Posted May 18, 2018 Posted May 18, 2018 Hi guys, I am wondering how I deal with this error message. Whenever I am trying to save a page I am getting this error when someone enters the same name in the "name" textbox. Here is my code <?php if ($input->post->reviews || $input->post->name) { // Save in the ProcessWire page tree; map submission to the template fields $np = new Page(); // create new page object $np->template = $templates->get("reviews"); $np->parent = $pages->get("/reviews/"); $name = $sanitizer->text($input->post->name); $email = $sanitizer->text ($input->post->email); $review = $sanitizer->text ($input->post->review); // Match up the sanitized inputs we just got with the template fields $np->of(false); $np->title = $name; $np->page_id = $page->id; $np->name = $name; $np->email = $email; $np->review = $review; $np->save(); } ?>
BitPoet Posted May 18, 2018 Posted May 18, 2018 Simply don't set a name, then PW will take the title you assigned and create a unique name from it by running it through $sanitizer->pageName and appending an incremental suffix if the name has already been taken. There can only be one page with a given name under the same parent. You can read some more about it in this discussion:
kixe Posted May 18, 2018 Posted May 18, 2018 1. Use the right sanitizer $email = $sanitizer->email($email); $pagename = $sanitizer->pageName($pagename); // OR $pagename = $sanitizer->pageNameUTF8($pagename); 2. Set adjustName to true in the save options array to make your page name unique $np = new Page() // ... $np->save(array('adjustName' => true)); 4
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