Jump to content

Preview Functionality, Theory question


Recommended Posts

Just as the title says, I want to know how a preview function is created, similar to wordpress, blogger, this forum, yada yada ... they all have a preview post function but I dont know how it does it. It doenst seem like the database is altered, but how does the preview function grab the content of the form as is and display it, is it js? then it loads it into a dummy page, say 'preview.php'? or is it database driven. If it is then preview becomes a button with 'submit' functionality right. but it doens't update the real database table, just the preview table. so how do you give a form dual submit functionality like that. to my knowledge you can put submit buttons all over the place but they all submit to where the form tag says to go.

 

Thanks

Link to comment
Share on other sites

No, JavaScript doesn't really play a role in this. I assume this is how it works -

 

1. You click the preview button (which has a name)

2. The script the form posts to check if you clicked the preview button, most likely with $_POST['preview'] or something.

3. If so, it would get the contents in the textarea, run it through some cleaning etc, and pass it to a function that handles the display. I'm guessing it's the same function that handles the display of your posts on the site. That function handles all the replace of BBCode to HTML etc and returns the output with proper slashes in place (if need be).

4. The function returns the string and it outputs it correctly on the page.

 

I'm not sure if it needs SESSION. I don't think it has to store anything in the DB either. I know Wordpress uses functions only, but you can create a class for it if you want. But generally, that's my POV on it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.