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

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 / 22
April 18, 2005
TABLE OF CONTENTS:
  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
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
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++)

{

       imagettftext($im,$fontSize,0,$nameArr[$i]->hpos,$vPos,

       $textColor,$fontPath,$nameArr[$i]->textStr);

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

}

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

imagepng($im);

imagedestroy($im);

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.

Conclusion

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
HTML ARTICLES

- HTML5 Boilerplate: Working with jQuery and M...
- HTML5 Boilerplate Introduction
- New API Platform for HTML5
- BBC Adopts HTML 5, Mozilla Addresses Issues
- Advanced Sticky Footers in HTML and CSS
- HTML and CSS Sticky Footers
- Strategy Analytics Predicts HTML5 Phones to ...
- HTML5 Guidelines for Web Developers
- Learning HTML5 Game Programming
- More Engaging CSS3 and HTML Background Effec...
- Engaging HTML and CSS3 Background Effects
- More Web Columns with CSS3 and HTML
- Columns with CSS3 and HTML
- Creating Inline-Block HTML Elements with CSS
- Drag and Drop in HTML5: Parsing Local Files

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



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