Lodius2000 Posted May 8, 2009 Share Posted May 8, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/157388-preview-functionality-theory-question/ Share on other sites More sharing options...
premiso Posted May 8, 2009 Share Posted May 8, 2009 They use Sessions to store the data and pass it to the preview script. If the preview is good, they use those session variables set to insert it into the database. Quote Link to comment https://forums.phpfreaks.com/topic/157388-preview-functionality-theory-question/#findComment-829660 Share on other sites More sharing options...
Lodius2000 Posted May 8, 2009 Author Share Posted May 8, 2009 so javascript passes the current value of the form fields to $_SESSION ? Quote Link to comment https://forums.phpfreaks.com/topic/157388-preview-functionality-theory-question/#findComment-829664 Share on other sites More sharing options...
Ken2k7 Posted May 9, 2009 Share Posted May 9, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/157388-preview-functionality-theory-question/#findComment-830150 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.