Solved

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

Posted on 2004-08-13
4
650 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 125 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Survey branching tutorial 11 72
[form-control] Retain values after a POST action 21 66
php output utf-8 problem 6 45
how can I see the time difference in only seconds? 4 34
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

740 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