Hopefully a simple one to answer but I really am bogged down on this. I have tried virtually everthing that I can find but must now admit that I cannot solve it while I am trying to learn at the same time.

I am trying to build a web page where the user can type a name of their choice in to a form, select a font style from a dropdown list and view an image of the name that they typed in the font that they choose.

I have based it on Stewart Rosenberger's Dynamic Heading Generator, but I am only using one .html page ( which I am calling PAGE.HTML) with the form calling my .php script (called HEADING.PHP).

Have managed the font changing part but I am tearing my hair out trying to get the image that the script creates to appear in the html page instead of appearing on it's own in a fresh browser window.

In detail, the php script is called by PAGE.HTML as follows (only the relevent html is shown here):

<body>
<form name="input" action="heading.php" method="get">
Enter your name:
<input type="text" name="text" value="Type Here"size="40" />
<br />
<input type="submit" value="Show Name" />
</form>
Your name:
<IMG SRC="heading.php">
</body>

This form calls HEADING.PHP where, after going through the font change and image creation parts, it outputs a.png image from imagepng() using the snippet seen here:

<?php
/
attempt to create an image containing the error message given.
if this works, the image is sent to the browser. if not, an error
is logged, and passed back to the browser as a 500 code instead.
/
function fatal_error($message)
{
// send an image
if(function_exists('ImageCreate'))
{
$width = ImageFontWidth(5) * strlen($message) + 10 ;
$height = ImageFontHeight(5) + 10 ;
if($image = ImageCreate($width,$height))
{
$background = ImageColorAllocate($image,255,255,255) ;
$text_color = ImageColorAllocate($image,0,0,0) ;
ImageString($image,5,5,5,$message,$text_color) ;

header('Content-type: image/png') ;
ImagePNG($image) ;
ImageDestroy($image) ;
exit ;
}
}

// send 500 code
header("HTTP/1.0 500 Internal Server Error") ;
print($message) ;
exit ;

}
?>

This puts the image that I want in a fresh browser window, but what I want to do is have the image appear in PAGE.HTML using the IMAGE tags that are below the form so that the user can try another font style without having to hit the back button.

It does not have to be IMAGE tags ie. could be <iframe> or whatever - just something that works!

Also PAGE.HTML can be PAGE.PHP if it needs php on it.

Any help very gratefully received.

    I hate iframes, so I'll tell you how to do it without them. 🙂

    This method will use the same page over and over again.

    1. use page.php

    2. have it output the form

    3. tell the form to point to itself (i.e., page.php)

    4. since you are using the "get" method, test isset($_GET['text'])

    5. if it exists, then below the form, place an image, using the heading.php file and the appropriate "get" line (i.e., heading.php?text=Yo+Dude ).

    6. if $_GET['text'] doesn't exist, output a default picture (i.e., heading.php?text=Try+Me ).

    of course, you could also use $_GET['text'] as the default value of the form textbox, so that they don't have to keep re-entering their name every time!

    Good luck!

      Many thanks coreyp_1 .

      Thats got me going again and the idea about keeping the name in the input box is an added bonus.
      🙂 🙂

        Write a Reply...