?
Solved

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

Posted on 2004-08-13
4
Medium Priority
?
657 Views
Last Modified: 2012-06-22
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
Comment
Question by:phpisthefuture
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 48

Accepted Solution

by:
hernst42 earned 500 total points
ID: 11791833
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
 
LVL 2

Author Comment

by:phpisthefuture
ID: 11794675
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
 
LVL 2

Author Comment

by:phpisthefuture
ID: 11795059
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
 
LVL 48

Expert Comment

by:hernst42
ID: 11797300
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question