Solved

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

Posted on 2004-08-13
4
615 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
  • 2
  • 2
4 Comments
 
LVL 48

Accepted Solution

by:
hernst42 earned 125 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now