[SOLVED] GD Printing issue...
Moderators: onion2k, General Moderators
[SOLVED] GD Printing issue...
Hello,
I'm new to PHP and GD, but have done a lot of graphics programming. I have a HTML FORM that when SUBMITTED invokes a PHP script that uses GD calls. I use POST to pass data, such as first_name, last_name, as well as numerous radio_button_values.... This PHP-GD script will then process and correctly display as I programmed it to within the browser, but when I try to print this browser display, the final output paper version is incorrect. Specifically, the data which originated or was defined by the end user in the FORM (for example first_name) does not appear on the final paper output. These data values are being correctly displayed within the browser, created using PHP GD calls such as "imagestring". For example if in the FORM I set first_name = "Terry", the PHP-GD script will make a call to "imagestring" to correctly display "Terry" within the browser, but when I then use the print feature of the browser, the contents of first_name will print as "". I had a suspicion that this was related to the scope of the data variables, but doing further debugging I removed all the GD calls and replaced the text display calls with simple PHP "echo" calls. This debug approach worked correctly within both the browser version as well as on the final printed version. My goal is to create a display that is a combination of both text and graphics, so I need to use GD calls, hence simple "echo" calls won't meet my overall needs. Something I noticed is that this is happening only to the data values that originated in the FORM and which are obtained via a $_POST call from within the PHP-GD script. It is as if the data that gets sent to the printer is simply the PHP-GD script without the ability to get at the user-defined FORM data. Any idea how to resolve this?
TIA
-T
I'm new to PHP and GD, but have done a lot of graphics programming. I have a HTML FORM that when SUBMITTED invokes a PHP script that uses GD calls. I use POST to pass data, such as first_name, last_name, as well as numerous radio_button_values.... This PHP-GD script will then process and correctly display as I programmed it to within the browser, but when I try to print this browser display, the final output paper version is incorrect. Specifically, the data which originated or was defined by the end user in the FORM (for example first_name) does not appear on the final paper output. These data values are being correctly displayed within the browser, created using PHP GD calls such as "imagestring". For example if in the FORM I set first_name = "Terry", the PHP-GD script will make a call to "imagestring" to correctly display "Terry" within the browser, but when I then use the print feature of the browser, the contents of first_name will print as "". I had a suspicion that this was related to the scope of the data variables, but doing further debugging I removed all the GD calls and replaced the text display calls with simple PHP "echo" calls. This debug approach worked correctly within both the browser version as well as on the final printed version. My goal is to create a display that is a combination of both text and graphics, so I need to use GD calls, hence simple "echo" calls won't meet my overall needs. Something I noticed is that this is happening only to the data values that originated in the FORM and which are obtained via a $_POST call from within the PHP-GD script. It is as if the data that gets sent to the printer is simply the PHP-GD script without the ability to get at the user-defined FORM data. Any idea how to resolve this?
TIA
-T
The only way that I can think of for this happening is if the "Print" button resubmits an HTTP request to get the page to print .. and thus the GD image is returned without the user data .. but that sounds extremely unlikely. What exactly are you sending to the browser? Just an image, or image plus HTML?
That concerns me. You shouldn't be able to do that in a GD script.I removed all the GD calls and replaced the text display calls with simple PHP "echo" calls
GD priting issue, GET works, POST does not...
hawleyjr | Please use
hawleyjr | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
At the bottom of this messages is the content of 3 files (form.htm, simple-text.php, simple-graphics.php )
to illustrate the issue. I have also included some instructions:
1.) Save each file to a server location and display form.html from the server, note must do this on the net, not local unless you have some way of making php work locally
2.) Next fill in the text versions first name with some data.
3.) Submit the text version, then use the browsers print menu to print - look at the paper and you will see the data printed.
4.) Back up to the Form.html display
5.) fill in the first name for the graphics version and submit
6.) Now, from the browser print menu print the page - the data will not be printed
Note, I was able to get this working when I changed from POST to GET
I am using IE 6.0.2800.1106 with numerous updates. Our IS guys keep our systems up-to-date.
This is part of an online survey system and a GET line could get rather long (30+variables)
Here are the file names and content as requested:
form.html
simple-text.php
simple-graphics.phpCode: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title>CSS Survey (PHP format)</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<h1>CSS Survey</h1>
<form name="form1" method="get" action="simple-text.php">
<table border="0" >
<b>TEXT VERSION</b>
<td><b>First Name </td>
<td><input type="text" name="q2" size="20"><br></td>
<td><input type=submit value="Submit" ></td>
<td><input type=reset value="Reset" ></td>
</table>
</form>
<form name="form1" method="get" action="simple-graphics.php">
<table border="0" >
<b>GRAPHICS VERSION</b>
<td><b>First Name </td>
<td><input type="text" name="q2" size="20"><br></td>
<td><input type=submit value="Submit" ></td>
<td><input type=reset value="Reset" ></td>
</table>
</form>
</body>
</html>Code: Select all
<?php
$im = @ImageCreate (769, 1005);
$q2 = $_POST[ 'q2' ];
//$q2 = $_GET[ 'q2' ];
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 0);
$xloc=10;
$yloc=15;
imagestring($im, 5, $xloc, $yloc, "Graphics Version Name: ".$q2, $textcolor);
ImagePng ($im);
?>
<?php
$q2 = $_POST[ 'q2' ];
// $q2 = $_GET[ 'q2' ];
echo "Text Version Name: ".$q2;
?>Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]This is the problem .. you've embedded the image data in an HTML page .. something that only IE can handle, and with very unpredictable results.Code: Select all
<?php $im = @ImageCreate (769, 1005); $q2 = $_POST[ 'q2' ]; //$q2 = $_GET[ 'q2' ]; $bg = imagecolorallocate($im, 255, 255, 255); $textcolor = imagecolorallocate($im, 0, 0, 0); $xloc=10; $yloc=15; imagestring($im, 5, $xloc, $yloc, "Graphics Version Name: ".$q2, $textcolor); ImagePng ($im); ?> <?php $q2 = $_POST[ 'q2' ]; // $q2 = $_GET[ 'q2' ]; echo "Text Version Name: ".$q2; ?>
Output a page of HTML from this script, and have an <img src="graphic.php?q2=$_POST['q2']"> line in it for the graphic.