[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 667
  • Last Modified:

PHP Form Output in TextArea & HTML source of output in another TextArea (on the same page)

Hi everybody
I have created a php form, and script works fine. But I would like the user to be able to see the form output in a text area on the same page and the html source of the output on another text area, again on the same page.
Here's the link of the form I have created (First text area for form output, and the one below is for html source):
http://www.freeauctionscripts.com/crosspromotion/
I know the function for converting the output of a variable to html source;
For instance:
-------------------------
 $f1 = $_POST['f1'];
 $f1= "<table><tr><tdwidth=100>".$f1."</td></tr></table>";  
 $f1htm = str_replace("<","&lt;",$f1);
-------------------------
But I don't know how to make it work in my script since there's not one output which I could call $output and create a new variable called $htmlsourceofoutput . I am totally lost and I need urgent help.
Thanks in advance.

And here's the PHP part of the code I have written (I am a newbie on PHP and I don't think my code is great but it works  ).
-------------------------
<html>
<head>
<title>Ebay Auctions Cross Promotion Tool</title>
<link href="/style.css" rel="stylesheet" type="text/css">
<script language=JavaScript src="picker.js"></script>
<style type="text/css">
<!--
.style1 {color: #FF0000}
-->
</style>
</head>
<body>
<?php include "../menu.inc"?>
<?php
// if submit pressed, then start processing form
if ($submit) {

// set variables from form input
    $twidth = $_POST['twidth'];
    $theight = $_POST['theight'];
      $target = $_POST['target'];
      $rows = $_POST['rows'];
      $border = $_POST['border'];
      $thumbborder = $_POST['thumbborder'];
      $font = $_POST['font'];
      $fontsize = $_POST['fontsize'];
      $fontcolor = $_POST['fontcolor'];
      $title = $_POST['title'];
      $font2 = $_POST['font2'];
      $fontsize2 = $_POST['fontsize2'];
      $fontcolor2 = $_POST['fontcolor2'];
      $footer = $_POST['footer'];
      $storeurl = $_POST['storeurl'];
      $f[0] = $_POST['f1'];
      $f[1] = $_POST['f2'];
      $f[2]= $_POST['f3'];
      $f[3]= $_POST['f4'];
      $f[4]= $_POST['f5'];
      $f[5]= $_POST['f6'];
      $f[6]= $_POST['f7'];
      $f[7]= $_POST['f8'];
      $f[8]= $_POST['f9'];
      $f[9]= $_POST['f10'];
      $imglink = "http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&item=";
      $imgsrc = "http://thumbs.ebay.com/pict/";
      $storeurl = $_POST['storeurl'];
      $jpg=".jpg";
//set counter to zero      
      
      if  ($title !="")
      {
echo "<table align=\"center\"><tr><td><font color=\"$fontcolor\" size=\"$fontsize\" face=\"$font\"><center>$title</center></font></td></tr></table>";      
}
//Start creating table
echo "<table border=\"$border\" align=\"center\">";

echo "<tr>";

$c = 0;
//Start do while
do
{
            
      $totalauctions = $c + 1;
      $result = $totalauctions % $rows;
      //Start if/break to check empty fields. If input field is empty,then jump out of do/while.
      if  ($f[$c] =="")
      {
      break;
      }//End if/break

if ($totalauctions <= $rows) {
echo "<td width=\"$twidth\" height=\"theight\"><a href=\"$imglink$f[$c]\" target=\"$target\"><img src=\"$imgsrc$f[$c].jpg\" width=\"$twidth\" height=\"$theight\" border=\"$thumbborder\"></a></td>";

}
elseif ($result != 1) {
echo "<td width=\"$twidth\" height=\"theight\"><a href=\"$imglink$f[$c]\" target=\"$target\"><img src=\"$imgsrc$f[$c].jpg\" width=\"$twidth\" height=\"$theight\" border=\"$thumbborder\"></a></td>";
}
else {
echo "<tr>";

//Create column
echo "<td width=\"$twidth\" height=\"theight\"><a href=\"$imglink$f[$c]\" target=\"$target\"><img src=\"$imgsrc$f[$c].jpg\" width=\"$twidth\" height=\"$theight\" border=\"$thumbborder\"></a></td>";

//End row


}

$c = $c + 1;
}
while ( $c <= 10 ) ;


//Checks 10 times within do while loop
echo "</table>";
      if  ($footer !="")
      {
echo "<table align=\"center\"><tr><td><font color=\"$fontcolor2\" size=\"$fontsize2\" face=\"$font2\"><center>$footer</center></font></td></tr></table>";
}
//Check if Store URL entered
      if  ($storeurl =="")
      echo "";
      else{
echo "<table align=\"center\"><tr><td><font color=\"$fontcolor2\" size=\"$fontsize2\" face=\"$font2\"><center>Please also visit our <a href=\"$storeurl\" target=\"$target\">Ebay Store</a> </center></font></td></tr></table>";
}
}
else {
?>//HTML FORM STARTS HERE...First TextArea is named "formoutput" and second one is "formoutputhtml"
--------------------------
0
phpisthefuture
Asked:
phpisthefuture
  • 2
  • 2
1 Solution
 
hernst42Commented:
have a look at the output buffering of PHP http://de3.php.net/manual/en/ref.outcontrol.php

e.g.
 if ($submit) {
*    ob_start()
....

}
* $renderoutput = ob_get_contents();
*  ob_end_flush();
}
else {

* indicates lines to add

Then variable $renderoutput contains all the output of the if condition.

To print that output use htmlspecialchars($renderoutput). Thats the better way than escaping it with str_replace

0
 
phpisthefutureAuthor Commented:
And how do I print in textareas? I have tried;
<textarea id="formoutput" name="formoutput" ROWS=10 COLS=90><?php echo $renderoutput ?> </textarea>
and for the second one (html code);
<textarea id="formoutputhtml" name="formoutputhtml" ROWS=10 COLS=90><?php echo htmlspecialchars($renderoutput) ?></textarea>
Even though the action of the form is <?php echo $PHP_SELF?> it still doesn't print in textareas?
Thanks
0
 
phpisthefutureAuthor Commented:
Ok I took off the first text area and my code works fine. It prints the output and below prints the html code. I have two questions. It prints the output at the beginning of the page too.
Please check;
http://www.freeauctionscripts.com/crosspromotion/
just click preview, you'll see.
And my second question is;
I want to the user to be able to see the options he has selected after clicking preview. Example:
User inputs 5 auction numbers and clicks preview, and he'll get the output but can't add another one 6th one, he has to input all of them again. (Same for font/color etc options too)
Is there a way to cache or sth. the form fields?
Thanks
0
 
hernst42Commented:
use something like:

<input name="fx" type="text" id="fx" value="<?=htmlspecialchars($_REQUEST['fx'])?>">


for additional questions see:
http://www.experts-exchange.com/Web/Web_Languages/PHP/help.jsp#hi107
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now