Click to See Complete Forum and Search --> : Preview button not sending form data


ApletFX
11-18-2003, 09:40 PM
Hello, I am working on a message forum and have found myself in a jam. Hopefully you guys can help.

I have a form with both a preview button and a submit button. The preview button targets a popup window to a specified size. I need the form data to post to that popup page without actually submitting the page. I want the visitor to preview the post before submitting the form to the DataBase. below is the code that I have so far. The button is working, it generates a popup window as it should but does not send the data. Here is a link to see a work up of the form

http://pixeljunkie.org/forum/inc_replytest.cfm

<script language="javascript">
function WinOpen(url,x,y) {
var attributes = "toolbar=no,scrollbars=yes,resizable=yes,width=" + x + ",height=" + y;
msgWindow=window.open(url,"WinOpen",attributes);
}
</script>


<form action="index.cfm" method="post" enctype="multipart/form-data" name="PostTopic" id="PostTopic">

<textarea name="message" cols="60" rows="8" id="message"></textarea>

<input name="Preview" type="button" class="normalbuttons" onclick="WinOpen('previewmessages.cfm','550','400'); return true;" value=" Preview ">

<input type="submit" name="Sumbit" class="normalbuttons" value=" Reply to Post " onClick="if(this.value == ' Reply to Post ') this.form.submit(); this.value = ' Please Wait... ';">

Thanks in advance for your help

Pittimann
11-19-2003, 05:10 AM
Hi ApletFX!

Use this as your "previewmessages.cfm":

<html>
<head>
<title>Preview Post</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../css/pixeljunkie.css" rel="stylesheet" type="text/css">
</head>
<body background="../images/interface/background_FFFFFF.gif" text="#77753A" link="#990000" vlink="#666666" alink="#000000">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#77753A">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td bgcolor="#CBCBB3">
<p>&nbsp; <b>Preview Reply Post</b></p>
</td>
</tr>
<tr>
<td valign="top" bgcolor="#FFFFFF">
<table width="100%" height="100" border="0" cellpadding="8" cellspacing="0">
<tr>
<td>
<p>
<script language="JavaScript" type="text/javascript">
<!--
document.write(opener.document.forms.PostTopic.message.value);
//-->
</script>
</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<p align="center"><a href="javascript:window.close()" onMouseOver="window.status='Close Window';return true" onMouseOut="window.status='';return true">Close
Window</a></p>
</body>
</html>

This will at least display the message without line breaks :(
Maybe I try to work on that later...

Cheers - Pit

Pittimann
11-19-2003, 05:27 AM
Hi again!

If you use this instead of just document.write the textarea's value:

<script language="JavaScript" type="text/javascript">
<!--
temp=opener.msgvar;
out="\r\n";
while (temp.indexOf(out)>-1) {
add = "<br>";
pos= temp.indexOf(out);
temp = "" + (temp.substring(0, pos) + add + temp.substring((pos + out.length), temp.length));
}
msgvar=temp;
document.write(msgvar);
//-->
</script>

and add the following to your WinOpen-function:

function WinOpen(url,x,y) {
var attributes = "toolbar=no,scrollbars=yes,resizable=yes,width=" + x + ",height=" + y;
msgvar=document.forms.PostTopic.message.value;
msgWindow=window.open(url,"WinOpen",attributes);
}

it will work. I'm sure there will be more professional solutions in Javascript. I would do stuff like that in PHP...

Cheers - Pit

ApletFX
11-19-2003, 09:06 AM
Thanks. I am sure either method will work for plain text. However I am also using a custom function on the previewmessage.cfm that converts the psuedohtml to regular html. ie smiles, colors, and formatting. I must get the form element "message" as a variable that way I can manipulate the output. in my example my message contains a text emoticon for a smile, hwever when you see it on screen it replaces the smile with a graphic for smile. Basicly what I am saying here is that I do not need to format the text I just need to be able to access it.


CODE IN PREVIEWMESSAGE.CFM
<cfparam name="message" default="Sorry, this option is not working yet. :)">
<cfinclude template="pseudocode.cfm">
<p><cfoutput>#replace(themessage,Chr(13),"<br>", "all")#</cfoutput></p>

Pittimann
Is it possiable to write to a variable? if so what might that look like.

At least I have a good idea as to what I was doing wrong to begin with. If you have anyother ideas please let me know.