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
https://forums.phpfreaks.com/topic/157388-preview-functionality-theory-question/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.