Page 1 of 1

[SOLVED] GD Printing issue...

Posted: Mon Apr 17, 2006 5:15 pm
by tulanch
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

Posted: Mon Apr 17, 2006 5:17 pm
by hawleyjr
Moved to PHPGD.com

Posted: Mon Apr 17, 2006 8:38 pm
by feyd
Can we see an example of this? Best if we can see an actual in-page (not a screenshot) reproduction of the problem.

Posted: Tue Apr 18, 2006 3:37 am
by onion2k
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?
I removed all the GD calls and replaced the text display calls with simple PHP "echo" calls
That concerns me. You shouldn't be able to do that in a GD script.

GD priting issue, GET works, POST does not...

Posted: Tue Apr 18, 2006 9:40 am
by tulanch
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.php

Code: 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;
?>
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]

Posted: Tue Apr 18, 2006 4:09 pm
by onion2k

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;
?>
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.

Output a page of HTML from this script, and have an <img src="graphic.php?q2=$_POST['q2']"> line in it for the graphic.

Posted: Tue Apr 18, 2006 6:03 pm
by tulanch
success!

thanks

-T