is there a sane way to "preview before post"

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
goodmanbrown
Forum Newbie
Posts: 1
Joined: Sat Jul 19, 2003 12:16 am

is there a sane way to "preview before post"

Post by goodmanbrown »

I am working on a site that allows users to post text. So it's a little bit like a forum, except that the text they are posting may be quite long. Say, 20 - 30 standard pages of text, typically, and possibly longer. It is important that the users be able to preview their submission before comitting it to the database. The only way I have been able to implement this, so far, is to echo the text to the preview page, and then hide the same text in a form input field.

Something like this:

<!-- display the preview text to the user -->
<?php echo($text); ?>

<!-- ask if the user wants to comit the text to the db -->
<form ...>
<input type='hidden' value='<?php echo($text); ?>' ... />
<input type="submit' value='Save Text' />
</form>

The obvious problem with this is that it doubles the amount of text being sent to the browser. For a brief forum posting, this is no biggie, but when it is 30 pages, that could seriously bog down users on slow connections.

Is there a better way to do the preview? Is there some way to keep the $text variable alive on the server, so that it isn't necessary to store it in the hidden form field? If there isn't, do people think it would be better or worse to store the text in a temporary table in the database, and then re-insert it into a live table once the user confirms?

If anyone has any pointers to offer, I look forward to reading them.
User avatar
Fredix
Forum Contributor
Posts: 101
Joined: Fri Jul 18, 2003 2:16 pm
Location: Wehr (Eifel) Germany
Contact:

Post by Fredix »

You can open a new window with the preview text if the post-writer is satisfied he can return to his post editing window and click submit.
I think thats a way, isn't it? ;)
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

...

Post by kettle_drum »

Why not just save the text they entered to a table called check or something in your database - then simply pass the record id of it in the page. Then after they have checked it save the edited version to the real database and delete the check version.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Split into chapters & submit / preview one chapter at a time?
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Post by xisle »

Add the post to the database and set a flag "approved=NOW()", once they have previewed and given the ok.
Get fancy and delete the record if they 'cancel' before approval.
Post Reply