Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/67707-solved-preview-button/
Share on other sites

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...
}

Link to comment
https://forums.phpfreaks.com/topic/67707-solved-preview-button/#findComment-340166
Share on other sites

@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?

Link to comment
https://forums.phpfreaks.com/topic/67707-solved-preview-button/#findComment-340190
Share on other sites

@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

Link to comment
https://forums.phpfreaks.com/topic/67707-solved-preview-button/#findComment-340198
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/67707-solved-preview-button/#findComment-340204
Share on other sites

<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 ;D 

Link to comment
https://forums.phpfreaks.com/topic/67707-solved-preview-button/#findComment-340214
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/67707-solved-preview-button/#findComment-340217
Share on other sites

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  :(

Link to comment
https://forums.phpfreaks.com/topic/67707-solved-preview-button/#findComment-340436
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/67707-solved-preview-button/#findComment-340906
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/67707-solved-preview-button/#findComment-340924
Share on other sites


<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

Link to comment
https://forums.phpfreaks.com/topic/67707-solved-preview-button/#findComment-340945
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.