Log in

View Full Version : code check please



bwc
06-10-2009, 07:07 AM
Hello .
I am trying to print command this. I understand you use javascript window.print but how do I do this? I know you can not mix it like this. But I want to print the gets and image and words ID# and Member Since in control sized window and Print Command. Any ideas?
Thanks


<table width="280"><tr><td valign="center">
<img src="http://www.domain.com/media/images/badgelogo.gif"><br>
<?= $_GET["PrimPhoto"]; ?><br>
<?= $_GET["Name"]; ?><br>
<?= $_GET["Title"]; ?><br>
ID# <?= $_GET["ID"]; ?><br>
Member Since
<?= $_GET["DateReg"]; ?>
</div><br>
<form id="printMe" name="printMe"> <input type="button"
name="printMe" onClick="printSpecial()" value="Print Badge"> </form>
</td></tr></table></center>

forum_amnesiac
06-10-2009, 01:55 PM
I'm not sure I fully understand your requirement but I've modified your code.

There is now a button that says 'Prepare Badge', this opens a window with the badge preview inside and a button that allows the javascript window.print function to be used to print the contents of the popup.

with PHP I personally prefer to create PDF documents, I find ezPDF quite easy to use.


<SCRIPT LANGUAGE="JavaScript">
function openindex()
{
OpenWindow=window.open("", "newwin", "height=250, width=250,toolbar=no,scrollbars="+scroll+",menubar=no");
OpenWindow.document.write("<TITLE>Title Goes Here</TITLE>");
OpenWindow.document.write("<BODY BGCOLOR=pink>");
OpenWindow.document.write("<h1>Test!</h1>");
OpenWindow.document.write("Your Photograph is : <?php echo $var1; ?><br>");
OpenWindow.document.write("Your Name is : <?php echo $var2; ?><br>");
OpenWindow.document.write("Your Title is : <?php echo $var3; ?><br>");
OpenWindow.document.write("Your ID is : <?php echo $var4; ?><br>");
OpenWindow.document.write("<br>");
OpenWindow.document.write("<br>");
OpenWindow.document.write('<form id="printMe" name="printMe"> <input type="button" name="print" onClick="window.print()" value="Print Badge"> </form><br>');

OpenWindow.document.write("</BODY>");
OpenWindow.document.write("</HTML>");

OpenWindow.document.close()
self.name="main"
}
</SCRIPT>

<table width="280"><tr><td valign="center">
<img src="http://www.domain.com/media/images/badgelogo.gif"><br>
<?
$var1="your photo";
$var2="your name";
$var3="Title";
$var4="ID";
?>
<?= $_GET["PrimPhoto"]; ?><br>
<?= $_GET["Name"]; ?><br>
<?= $_GET["Title"]; ?><br>
ID# <?= $_GET["ID"]; ?><br>
Member Since
<?= $_GET["DateReg"]; ?>
</div><br>
<form id="printMe" name="printMe"> <input type="button"
name="printMe" onClick="openindex()" value="Prepare Badge"> </form>
</td></tr></table></center>

bwc
06-10-2009, 10:51 PM
Thanks for answering. I like the idea. But how do you suggest they upload their picture and have it show along with all info?
Also would I save this file as .html or .php?

bwc
06-11-2009, 12:15 AM
Ok I tried your script and did not get the variables. Contact you PM

forum_amnesiac
06-11-2009, 08:22 AM
This file is PHP.

I would suggest that there is a previous form with a line for <input type="file">, to get the image as well as the rest of their information.

If you want you can have the image file transferred to a directory on your domain and the path to it and all their other details stored in a database.

The next step in the process, a second page, would be to present them with details of what they have entered and the option to print.

Another option would be to do all of this on a single PHP page, using if (isset($_POST['submit']));, and only presenting the print option if it passes the test.

This way you don't have to store anything on your domain.

As they say 'the choice is yours', it really depends on how, and why, you are taking these details.

bwc
06-12-2009, 03:14 PM
I tried some things but did not get it to work. Thanks

heavensgate15
06-16-2009, 08:43 PM
waaaaaaa.... Is it possible to combine php and javascript?

forum_amnesiac
06-17-2009, 06:18 AM
It certainly is, there are a number of ways to do this.

This is what I use to have an 'alert' feature in my PHP:


function alert($alert) {
$out .='<script type="text/javascript">
alert("'.$alert.'");
</script>
';

print $out;

}

or you can echo the javascript lines along with the HTML, you can also break out of PHP to use HTML and put normal javascript in the <head> section

traq
06-17-2009, 07:39 AM
Think of your php code as a set of instructions that your server uses to write your web pages for you.

Uh... yeah.
That's actually a fairly literal analogy. :D

So, anything you can write, php can write too.