Hey everyone!
I'm building a form that submits / updates articles for a website. I want to include the ability for all articles being written to be 'previewed' before being submitted live. So my form has two buttons: "Submit Article" (or "Update Article", depending..) and "Preview Article". I want post previews to open in a new window (similar to how Wordpress does it) and be an actual view of how the post will look when published.
Our article table in the database allows for articles to have an article 'status' and only articles where the status is set to 'published' are pulled for the public to view. So here's how I was planning to tackle this, but I'm wondering if I'm making it more complex than I need to? Any thoughts would be appreciated!
My idea..:
The 'Preview Article' makes an AJAX call that inserts a new record into the database's article table with the article status of 'post_preview' and then pops open a new window that pulls the article information just inserted using the same template the main article page does so that it looks like a live article posting.
Closing this pop up window, changing some things on the parent window form and hitting preview again would do the same thing.
Finally, when clicking the "Submit Article", the real information would be inserted into the database, and a clean up "DELETE articles where status = 'post_preview'" would be run to get rid of those constantly growing previews.
If I didn't do it this way I'm unsure of how to open the article in a new window containing the information from the updated article without effecting the real data if it is a article update.
Any thoughts? Thanks!