Home arrow HTML arrow Page 8 - Submitting a Form Using an Image Tag

Submitting a Form Using an Image Tag

There are a number of ways to make the forms on your website more user friendly. This article will explain one way of doing this, which eliminates a page reload and replaces it with an image generated on the server.

Author Info:
By: Chris Root
Rating: 5 stars5 stars5 stars5 stars5 stars / 25
April 18, 2005
  1. · Submitting a Form Using an Image Tag
  2. · Submitting a Form
  3. · Processing the Form
  4. · The Server Side Code
  5. · GD Methods
  6. · Handling the Name
  7. · The TextBox Class
  8. · From the Top

print this article

Submitting a Form Using an Image Tag - From the Top
(Page 8 of 8 )

We actually jumped ahead in the code in order to explain what this application needed to accomplish and how it would go about it. Now let's look at it in order of execution.

//load the background image

$im = imagecreatefrompng("images/confirm.png");

$textColor = imagecolorallocate($im,255,255,255);//allocate white

//get text dimensions

$nameArr = handleName($fontSize,$fontPath,$im,$str);

$vPos = getVerticalPosition($im);//get vertical coordinate for all text

for($i = 0;$i < count($nameArr);$i++)




       $vPos = $vPos + $nameArr[$i]->h;


header("Content-type: image/png");



Once we have all the coordinates needed to place the text, it's time to actually write it to the image. The imagettftext function is used for each text box. Arguments are as mentioned before: image resource, the font size, the angle, the horizontal coordinate, the vertical position, the text color that we allocated, the font and the text string. Notice that at the end of each loop iteration, the height of the current text block is added to the vertical position. This will put the next text block below the previous.

Once all the text is placed, the HTTP header is sent, announcing that we are sending an image of type png. The imagepng() function then sends the image, and we use imagedestroy() to close the stream.


As you can see, the hardest part of all this was working with the text, and this example does not show what to do with the email address or entering the user in the contest, as your use of this form submission technique will depend on the situation. How the server side code works will vary depending on what platform you are using.

You now have an understanding of how an image tag can be used to submit a form and create a better user experience for the visitors of your site. For more information on GD and PHP, take a look at the PHP documentation at php.net

DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus

- Does HTML5 Need a Main Element?
- Revisiting the HTML5 vs. Native Debate
- HTML5: Not for Phone Apps?
- HTML5 or Native?
- Job Hunting? Freelancer.com Lists This Quart...
- HTML5 in the News
- Report: HTML5 Mobile Performance Lags
- The Top HTML5 Audio Players
- Top HTML5 Video Tutorials
- HTML5: Reasons to Learn and Use It
- More of the Top Tutorials for HTML5 Forms
- MobileAppWizard Releases HTML5 App Builder
- HTML5 Boilerplate: Working with jQuery and M...
- HTML5 Boilerplate Introduction
- New API Platform for HTML5

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials