Frank Vèssia Posted September 13, 2011 Share Posted September 13, 2011 I perform a form submission via jquery. This form create a page and than i display the results below the form. I can display all my fields (after $page->save()) but not the $page->created property. I need to refresh the page to see the correct date 1 Link to comment Share on other sites More sharing options...
ryan Posted September 13, 2011 Share Posted September 13, 2011 Some properties are only populated at page load time. When you create a new page in memory and save it, that page has still never been loaded from the database. As a result, it won't have created/modified properties since those are DB generated. PW doesn't automatically reload a page from the DB when you save it. But you can reload it yourself: $page = $pages->get($page->id); However, I think an even better strategy is to perform a redirect after you've committed any kind of major changes. That ensures that you are dealing with a fresh copy of everything and prevents a browser reload/refresh from re-posting your form and potentially creating a duplicate. So I would do something like this: <?php $template = $templates->get('new_page_template'); $parent = $pages->get('/path/to/parent/'); if($input->post->submit == 'save') { $p = new Page(); $p->parent = $parent; $p->template = $template; // ...populate the page... if($p->save()) { $session->newPageID = $p->id; $session->redirect('./'); } else { echo "error saving page"; } } else if($session->newPageID) { $p = $pages->get($session->newPageID); // a little security check, that may not be necessary since we're using $session // but i always veer on the side of more security. if($p->parent->id == $parent->id && $p->template === $template) { // display the results } } 1 Link to comment Share on other sites More sharing options...
Frank Vèssia Posted September 13, 2011 Author Share Posted September 13, 2011 It works perfectly, thanks 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