Fadion Posted September 3, 2007 Share Posted September 3, 2007 Im working on this custom cms where the site admin can edit articles in a wysiwyg editor. I had an idea to make a preview button which opens a new window with the real site template and preview the content of the editor (textarea) in the template. I am not figuring out how to make that button open the new page and get the value of the textarea in the same time. What i have so far is post the data after a button is pressed and check with isset($_POST['preview_btn']) if is pressed preview or submit, but i have no idea how to automatically open a new window after this. Any suggestion should be very helpful. Quote Link to comment https://forums.phpfreaks.com/topic/67707-solved-preview-button/ Share on other sites More sharing options...
Timma Posted September 3, 2007 Share Posted September 3, 2007 Well you could probably make each button open up a different page, for example, make it open blah.php?preview or blah.php?submit Quote Link to comment https://forums.phpfreaks.com/topic/67707-solved-preview-button/#findComment-340129 Share on other sites More sharing options...
Fadion Posted September 3, 2007 Author Share Posted September 3, 2007 The submit button sends post data which are then processed and make an update query. From what i can think now, the preview button must be in the same form as the submit one, or how could i get the post value of the textarea? Quote Link to comment https://forums.phpfreaks.com/topic/67707-solved-preview-button/#findComment-340132 Share on other sites More sharing options...
hostfreak Posted September 3, 2007 Share Posted September 3, 2007 You could store the values in the $_SESSION superglobal array, then use javascript (window.open()) to load the preview page. Then being as the variables would be stored in the $_SESSION superglobal array, you could echo them for display etc. Quote Link to comment https://forums.phpfreaks.com/topic/67707-solved-preview-button/#findComment-340157 Share on other sites More sharing options...
Fadion Posted September 3, 2007 Author Share Posted September 3, 2007 Yes i can use window.open() in the button onClick, but how am i gonna pass the value of the textarea to the session if the form which contains it isnt submitted? Quote Link to comment https://forums.phpfreaks.com/topic/67707-solved-preview-button/#findComment-340164 Share on other sites More sharing options...
Timma Posted September 3, 2007 Share Posted September 3, 2007 But that is exactly what you do, submit it. Quote Link to comment https://forums.phpfreaks.com/topic/67707-solved-preview-button/#findComment-340165 Share on other sites More sharing options...
Fadion Posted September 3, 2007 Author Share Posted September 3, 2007 Thats what ive done, submit the form. The problem is that how can i open a new window with code after i submit the form. Lets say:  if(isset($_POST['preview'])){   $text = $_POST['textarea']; //load the text of the textarea   //then... } Quote Link to comment https://forums.phpfreaks.com/topic/67707-solved-preview-button/#findComment-340166 Share on other sites More sharing options...
teng84 Posted September 3, 2007 Share Posted September 3, 2007 have you tried ajax? i guess it might help say on click pass the value of that text area hmm!! Quote Link to comment https://forums.phpfreaks.com/topic/67707-solved-preview-button/#findComment-340175 Share on other sites More sharing options...
Timma Posted September 3, 2007 Share Posted September 3, 2007 In the same php file as the form, if it is php, make it post to itself and when it has got something, make it open the window. Quote Link to comment https://forums.phpfreaks.com/topic/67707-solved-preview-button/#findComment-340181 Share on other sites More sharing options...
Fadion Posted September 3, 2007 Author Share Posted September 3, 2007 @teng84 what do u mean? Even with ajax i may have the same problem  @timma thats how the script works, posts to itslef but as ive said it several time, what dont realize is how to open a new window after the form is submitted. If i use "onClick='window.open('somefile.php')" on the preview button, i wont have the post data of the textarea. Am i being clear, or u need any other info? Quote Link to comment https://forums.phpfreaks.com/topic/67707-solved-preview-button/#findComment-340190 Share on other sites More sharing options...
Timma Posted September 3, 2007 Share Posted September 3, 2007 Oh, maybe something to do with body onLoad or just execute the function in a <script> Quote Link to comment https://forums.phpfreaks.com/topic/67707-solved-preview-button/#findComment-340194 Share on other sites More sharing options...
teng84 Posted September 3, 2007 Share Posted September 3, 2007 @teng84 what do u mean? Even with ajax i may have the same problem  @timma thats how the script works, posts to itslef but as ive said it several time, what dont realize is how to open a new window after the form is submitted. If i use "onClick='window.open('somefile.php')" on the preview button, i wont have the post data of the textarea. Am i being clear, or u need any other info?  ajax can do that i have done something like that when the user clicks the name the window appear containing the value for the text box no diff with text area Quote Link to comment https://forums.phpfreaks.com/topic/67707-solved-preview-button/#findComment-340198 Share on other sites More sharing options...
Fadion Posted September 3, 2007 Author Share Posted September 3, 2007 I was just thinking of a way in javascript and ended with: Â onclick="alert(document.getElementById('textarea').value);" Â but im getting the initial value of the textarea, not the changed text. I just know some simple basic stuff in javascript so if u can explain it well and possibly provide some code, it would be great. Â EDIT: Probably i had to mention im using TinyMCE editor as my textareas. Quote Link to comment https://forums.phpfreaks.com/topic/67707-solved-preview-button/#findComment-340204 Share on other sites More sharing options...
Timma Posted September 3, 2007 Share Posted September 3, 2007 Better idea! Why not, when you click the preview button, make it post back to the page it was on, and then make it set the value of that textarea to the one that was there previously. Quote Link to comment https://forums.phpfreaks.com/topic/67707-solved-preview-button/#findComment-340207 Share on other sites More sharing options...
Fadion Posted September 3, 2007 Author Share Posted September 3, 2007 Timma, it still doesnt resolve the problem. As u say it would act as a submit button who posts the form and still i cant make it load a new page in a new window ??? Quote Link to comment https://forums.phpfreaks.com/topic/67707-solved-preview-button/#findComment-340209 Share on other sites More sharing options...
teng84 Posted September 3, 2007 Share Posted September 3, 2007 <html> <head> <script type="text/javascript"> function alertValue() Â { Â alert(document.getElementById('txt1').value); Â } </script> </head> <body> <textarea id="txt1"> </textarea> <br /> <input type="button" onclick="alertValue()" value="Alert value" /> </body> </html> Â that works with alert it will work in ajax for sure, i dont want to code that whole thing but with this you can have a great start ;DÂ Quote Link to comment https://forums.phpfreaks.com/topic/67707-solved-preview-button/#findComment-340214 Share on other sites More sharing options...
Timma Posted September 3, 2007 Share Posted September 3, 2007 That still does not resolve his main problem, getting the information that a user typed into that box. Quote Link to comment https://forums.phpfreaks.com/topic/67707-solved-preview-button/#findComment-340215 Share on other sites More sharing options...
teng84 Posted September 3, 2007 Share Posted September 3, 2007 That still does not resolve his main problem, getting the information that a user typed into that box. Â i dont know how and why GG want this but its doesnt look good to refresh the page to see the preview on the other window LOL Â for sure that dont solved the prob but if GG know AJAX then prob is solve Quote Link to comment https://forums.phpfreaks.com/topic/67707-solved-preview-button/#findComment-340217 Share on other sites More sharing options...
Fadion Posted September 3, 2007 Author Share Posted September 3, 2007 As it is a cms, i want the client to preview the content of the article before submiting. Actually it isnt very important, but just a feature i wanted to add and a "challenge" for myself. But i thought it a lot more easy in the beginning. Im no ajax expert but i doubt it would resolve my problem Quote Link to comment https://forums.phpfreaks.com/topic/67707-solved-preview-button/#findComment-340436 Share on other sites More sharing options...
Fadion Posted September 3, 2007 Author Share Posted September 3, 2007 Bump. Quote Link to comment https://forums.phpfreaks.com/topic/67707-solved-preview-button/#findComment-340899 Share on other sites More sharing options...
teng84 Posted September 3, 2007 Share Posted September 3, 2007 If you test my sample it shows an alert box displaying what yuo have type in your text area dude it no diff opening a new window to preview this may take a bit of work. see this sample sorry if i cant code this one for you but start here http://www.w3schools.com/php/php_ajax_database.asp I hope you know how to open a new window using JS so iguess you can do this one Quote Link to comment https://forums.phpfreaks.com/topic/67707-solved-preview-button/#findComment-340906 Share on other sites More sharing options...
teng84 Posted September 3, 2007 Share Posted September 3, 2007 or you can try just what this forum does to preview your post. Quote Link to comment https://forums.phpfreaks.com/topic/67707-solved-preview-button/#findComment-340911 Share on other sites More sharing options...
Fadion Posted September 3, 2007 Author Share Posted September 3, 2007 I test the javascript thing to get the textarea value, but as i previously said it shows the original value, not the modified one. For opening a new window with JS i can use window.open() but thats not my problem. What would i need ajax? What i want is get the value of the textarea and open a new window. Â In this forum, the preview area is on top of the editor. I can easily do that, but i want to open a new window as i cant preview a real site template inside a small area. Â Anyway thanks for helping. Quote Link to comment https://forums.phpfreaks.com/topic/67707-solved-preview-button/#findComment-340924 Share on other sites More sharing options...
teng84 Posted September 3, 2007 Share Posted September 3, 2007 <html> <head> <script type="text/javascript"> function alertValue() Â { Â //alert(document.getElementById('txt1').value); Â myWindow=window.open('','','width=200,height=100') myWindow.document.write(document.getElementById('txt1').value) myWindow.focus() Â Â } </script> </head> <body> <textarea id="txt1"> Hello world....This is a text area </textarea> <br /> <input type="button" onClick="alertValue()" value="Alert value" /> </body> </html> Â Â OOOOOOKKKKKKÂ hope this one help try Quote Link to comment https://forums.phpfreaks.com/topic/67707-solved-preview-button/#findComment-340945 Share on other sites More sharing options...
teng84 Posted September 3, 2007 Share Posted September 3, 2007 oooppp this is no php !!! Quote Link to comment https://forums.phpfreaks.com/topic/67707-solved-preview-button/#findComment-340947 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.