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