Luis Posted December 3, 2012 Share Posted December 3, 2012 Hey, I think I could need some little help. I got some Problems with deleting a page from the frontend. I´m trying the following: Click on a link and give this link via GET the $page-title. In the next step I render a form and put this GET Variable in a hidden field. After submit the script searches the page and delete it. But it always throws me an error. Here is my code so far from the delete page: <?php $choosen = $sanitizer->text($input->get->delpage); include ("./head.inc"); include ("./buchhaltungNavigation.php"); ?> <div class="row"> <div class="span12"> <hr /> <?php $success_message = "<h3 class='alert alert-success'>Gelöscht</h3>"; $success = false; // we assume it and set to true if form sent $error = false; // set and sanitize our form field values $form = array( 'delpage' => $sanitizer->text($input->post->delpage) ); $required_fields = array( ); // check if the form was submitted if($input->post->submit) { // determine if any fields were ommitted or didn't validate foreach($required_fields as $key => $value) { if( trim($value) == '' ) { $error_message = "<h3 class='error'>Please check that you have completed all the required fields.</h3>"; $error = true; } } // if no errors, delete the page if(!$error) { $c = $input->post->delpage; $p = $pages->get("/buchhaltung/buchungen/")->children("title=$c"); $p->delete(); echo $success_message; } } ?> <?php if(!$success) { ?> <?php if($error) { echo $error_message; } ?> <form action="./" method="post" id="submitform" class=""> <?php $delpage = $pages->get("/buchhaltung/buchungen/")->children("title=$choosen"); ?> <input type="hidden" name="delpage" id="delpage" value="<?php echo $delpage; ?>" /> <input type="submit" name="submit" value="submit" class="btn btn-primary" /> </form> <?php } else { echo $success_message; ?> <?php } ?> </div> </div> <?php include ("./foot.inc"); ?> Link to comment Share on other sites More sharing options...
arjen Posted December 3, 2012 Share Posted December 3, 2012 Would you be so kind to tell us which kind of error you are getting (possible with debug->true in config.php)? Link to comment Share on other sites More sharing options...
ryan Posted December 3, 2012 Share Posted December 3, 2012 I think that the error is here: $p = $pages->get("/buchhaltung/buchungen/")->children("title=$c"); $p->delete(); $p is a PageArray (the return value of the children() method), not a Page, and there is no delete() method on a PageArray. What I think you want is the child() method (which returns 1 page) rather than the children() method: $c = $sanitizer->selectorValue($input->post->delpage); $p = $pages->get("/buchhaltung/buchungen/")->child("title=$c"); if($p->id) $p->delete(); Also, you might want to use the 'name' or 'id' property rather than the title. The reason for that is that 'title' is not guaranteed to be unique, whereas 'id' is guaranteed to be unique system-wide, and 'name' is guaranteed to be unique for all children of a given parent. $name = $sanitizer->pageName($input->post->delpage); if(strlen($name)) { $p = $pages->get("/buchhaltung/buchungen/")->child("name=$name"); if($p->id) $p->delete(); } 2 Link to comment Share on other sites More sharing options...
Luis Posted December 4, 2012 Author Share Posted December 4, 2012 Ooooh shame on me... thank you Ryan. Link to comment Share on other sites More sharing options...
onjegolders Posted December 4, 2012 Share Posted December 4, 2012 Glad you got it sorted Luis! 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