Jump to content

Bad value for action attribute


vipsa

Recommended Posts

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>
Link to comment
https://forums.phpfreaks.com/topic/283712-bad-value-for-action-attribute/
Share on other sites

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.