vipsa Posted November 8, 2013 Share Posted November 8, 2013 (edited) Hi I have very little php experience and I battle to understand how it works so I really need explaining how certain things work. Like I have the following code: The line <form action="echo htmlentities($_SERVER['PHP_SELF']); ?>" method="GET"> says bad value and double white space in path which I cannot find as there are not white spaces in the path. Please help me understand this <?php if (isset($_GET['message'])) { // load font and image, calculate width of text $font = "times"; $size = 12; $image = imagecreatefrompng("button.png"); $tsize = imagettfbbox($size, 0, $font, $_GET['message']); // center $dx = abs($tsize[2] - $tsize[0]); $dy = abs($tsize[5] - $tsize[3]); $x = (imagesx($image) - $dx) / 2; $y = (imagesy($image) - $dy) / 2 + $dy; // draw text $black = imagecolorallocate($im,0,0,0); imagettftext($image, $size, 0, $x, $y, $black, $font, $_GET['message']); // return image header("Content-type: image/png"); imagepng($image); exit; } ?> <html> <head> <title>Button Form</title> </head> <body> <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="GET"> Enter message to appear on button: <input type="text" name="message" /><br /> <input type="submit" value="Create Button" /> </form> </body> </html> Edited November 8, 2013 by vipsa Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted November 8, 2013 Share Posted November 8, 2013 (edited) Do the form like this <form action="" method="GET"> leaving it blank will go to same page Removed my comment about no <?php opening tag, see it in code Edited November 8, 2013 by QuickOldCar Quote Link to comment Share on other sites More sharing options...
requinix Posted November 8, 2013 Share Posted November 8, 2013 There is nothing wrong with that line. What are you using that claims the line is bad? Does it know how to understand PHP code? Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted November 8, 2013 Share Posted November 8, 2013 (edited) I just tested this and worked fine, a few minor changes, you should add the ttf extension your font filename <?php if (isset($_GET['message']) && trim($_GET['message']) !='') { $message = trim($_GET['message']); // load font and image, calculate width of text $font = "times.ttf"; // does this font file exist same folder ? $size = 12; $image = imagecreatefrompng("button.png"); $tsize = imagettfbbox($size, 0, $font, $message); // center $dx = abs($tsize[2] - $tsize[0]); $dy = abs($tsize[5] - $tsize[3]); $x = (imagesx($image) - $dx) / 2; $y = (imagesy($image) - $dy) / 2 + $dy; // draw text $black = imagecolorallocate($image,0,0,0); imagettftext($image, $size, 0, $x, $y, $black, $font, $message); // return image header("Content-type: image/png"); imagepng($image); //frees image from memory imagedestroy($image); exit; } ?> <html> <head> <title>Button Form</title> </head> <body> <form action="" method="GET"> Enter message to appear on button: <input type="text" name="message" /><br /> <input type="submit" value="Create Button" /> </form> </body> </html> Edited November 8, 2013 by QuickOldCar Quote Link to comment Share on other sites More sharing options...
vipsa Posted November 8, 2013 Author Share Posted November 8, 2013 @requinix I am using netbeans 7.2 and it flags that line as BAD value for attribute action DOUBLE_WHITEPSPACE in PATHThere are no spaces in the path and if you run the code it gives an error Quote Link to comment Share on other sites More sharing options...
requinix Posted November 8, 2013 Share Posted November 8, 2013 (edited) https://netbeans.org/bugzilla/show_bug.cgi?id=195647 Basically, don't use the HTML validator on PHP files. Edited November 8, 2013 by requinix Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.