ankh2054 Posted May 12, 2014 Share Posted May 12, 2014 Hi all, One problem and one question: Problem: The below code does not update the body field attached to the template (discussions) Question: What type of redirect can I use to redirect session to newly created page after page save. Code // Process new page creation if($input->post->create_submit) { //Sanatize variables taking in the form data $title = $sanitizer->text($input->post->title); $body = $sanitizer->textarea($input->post->body); $p = new Page(); // create new page object $p->template = 'discussions'; // set template $p->parent = wire('pages')->get('/discuss/'); // set the parent $p->title = $title; // set page title (not neccessary but recommended) $P->body = $body; //Set the body $p->save(); } ?> <form class="form-horizontal" action="./" accept-charset="UTF-8" autocomplete="off" method="post"> <div class="form-group"> <label for="inputFullname3" class="col-sm-2 control-label">Title</label> <div class="col-sm-10"> <input type="text" class="form-control" name="title" placeholder="Enter the Title" > </div> </div> <div class="form-group"> <label for="inputEmail3" class="col-sm-2 control-label">Body</label> <div class="col-sm-10"> <textarea name='body' rows='5' cols='45' id='body' placeholder="Your message"></textarea> </div> </div> <button class="btn btn-lg btn-primary" type="submit" name="create_submit" value="create_submit">Create Discussions</button> </form> Link to comment Share on other sites More sharing options...
onjegolders Posted May 12, 2014 Share Posted May 12, 2014 Hi ankh, You have a capital $P on your variable. $P->body = $body; //Set the body This could be why the body is not getting updates. For the redirect you can use: $session->redirect("/"); Link to comment Share on other sites More sharing options...
ankh2054 Posted May 12, 2014 Author Share Posted May 12, 2014 thanks, how embarrassing For the redirect, I would like to redirect to the newly created page, $session->redirect("/"); seems to only redirect to my homepage. Link to comment Share on other sites More sharing options...
adrian Posted May 12, 2014 Share Posted May 12, 2014 $session->redirect($p->url); Link to comment Share on other sites More sharing options...
ankh2054 Posted May 12, 2014 Author Share Posted May 12, 2014 thanks Adrian, I ended doing this which also worked, but am going to change to yours as cleaner. $redname = $p->name; $session->redirect("/discuss/$redname"); 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