Author Topic: [SOLVED] Preview Button  (Read 1630 times)

0 Members and 1 Guest are viewing this topic.

Offline GuiltyGearTopic starter

  • Addict
  • Posts: 1,692
  • Gender: Male
    • View Profile
    • Laboratori.al - Creative Web Geeks
[SOLVED] Preview Button
« on: September 02, 2007, 08:07:49 PM »
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.

Offline Timma

  • Enthusiast
  • Posts: 80
    • View Profile
Re: Preview Button
« Reply #1 on: September 02, 2007, 08:10:46 PM »
Well you could probably make each button open up a different page, for example, make it open blah.php?preview or blah.php?submit

Offline GuiltyGearTopic starter

  • Addict
  • Posts: 1,692
  • Gender: Male
    • View Profile
    • Laboratori.al - Creative Web Geeks
Re: Preview Button
« Reply #2 on: September 02, 2007, 08:14:22 PM »
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?

Offline hostfreak

  • Devotee
  • Posts: 581
    • View Profile
    • Mach 5 Host
Re: Preview Button
« Reply #3 on: September 02, 2007, 08:54:42 PM »
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.
« Last Edit: September 02, 2007, 08:55:46 PM by hostfreak »

Offline GuiltyGearTopic starter

  • Addict
  • Posts: 1,692
  • Gender: Male
    • View Profile
    • Laboratori.al - Creative Web Geeks
Re: Preview Button
« Reply #4 on: September 02, 2007, 09:10:01 PM »
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?

Offline Timma

  • Enthusiast
  • Posts: 80
    • View Profile
Re: Preview Button
« Reply #5 on: September 02, 2007, 09:14:52 PM »
But that is exactly what you do, submit it.

Offline GuiltyGearTopic starter

  • Addict
  • Posts: 1,692
  • Gender: Male
    • View Profile
    • Laboratori.al - Creative Web Geeks
Re: Preview Button
« Reply #6 on: September 02, 2007, 09:18:47 PM »
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:

Code: [Select]
if(isset($_POST['preview'])){
    $text = $_POST['textarea']; //load the text of the textarea
    //then...
}

Offline teng84

  • Fanatic
  • Posts: 3,546
  • Gender: Male
    • View Profile
Re: Preview Button
« Reply #7 on: September 02, 2007, 09:43:48 PM »
have you tried ajax? i guess it might help say on click pass the value of that text area hmm!!  ::)

Offline Timma

  • Enthusiast
  • Posts: 80
    • View Profile
Re: Preview Button
« Reply #8 on: September 02, 2007, 09:53:40 PM »
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.

Offline GuiltyGearTopic starter

  • Addict
  • Posts: 1,692
  • Gender: Male
    • View Profile
    • Laboratori.al - Creative Web Geeks
Re: Preview Button
« Reply #9 on: September 02, 2007, 10:02:44 PM »
@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?

Offline Timma

  • Enthusiast
  • Posts: 80
    • View Profile
Re: Preview Button
« Reply #10 on: September 02, 2007, 10:08:52 PM »
Oh, maybe something to do with body onLoad or just execute the function in a <script>

Offline teng84

  • Fanatic
  • Posts: 3,546
  • Gender: Male
    • View Profile
Re: Preview Button
« Reply #11 on: September 02, 2007, 10:19:07 PM »
@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

Offline GuiltyGearTopic starter

  • Addict
  • Posts: 1,692
  • Gender: Male
    • View Profile
    • Laboratori.al - Creative Web Geeks
Re: Preview Button
« Reply #12 on: September 02, 2007, 10:36:17 PM »
I was just thinking of a way in javascript and ended with:

Code: [Select]
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.
« Last Edit: September 02, 2007, 10:38:21 PM by GuiltyGear »

Offline Timma

  • Enthusiast
  • Posts: 80
    • View Profile
Re: Preview Button
« Reply #13 on: September 02, 2007, 10:43:45 PM »
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.

Offline GuiltyGearTopic starter

  • Addict
  • Posts: 1,692
  • Gender: Male
    • View Profile
    • Laboratori.al - Creative Web Geeks
Re: Preview Button
« Reply #14 on: September 02, 2007, 10:46:58 PM »
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  ???